在<eof>附近的roblox Studio'end'预期(将关闭第1行的'function')

时间:2019-02-28 17:32:19

标签: lua roblox

当有人聊天“控制台打开”时,我尝试编写一些代码来在工作区中创建一个名为“控制台”的文件夹,但是当我在公共游戏中运行它时,有人说“关闭控制台”,则将其删除(因为没有在roblox Studio的测试模式下聊天),出现标题错误,并且在阅读了几则帖子后都没有答案。

game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
print("Connected")
if msg == "Console on" then
    console = Instance.new("Folder",workspace)
    console.name = "Console"
    print("Console Made")
elseif 
    msg == "Console off" then
        print("Console Destroyed")
        console:Destroy()
end
end)

1 个答案:

答案 0 :(得分:2)

如果您更一致地缩进代码,则将更容易发现语法错误在哪里:

game.Players.PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(msg)
        print("Connected")
        if msg == "Console on" then
            console = Instance.new("Folder",workspace)
            console.name = "Console"
            print("Console Made")
        elseif msg == "Console off" then
            print("Console Destroyed")
            console:Destroy()
        end
    end)

更清晰:

game.Players.PlayerAdded:Connect(
    function(plr)
        plr.Chatted:Connect(
            function(msg)
                print("Connected")
                if msg == "Console on" then
                    console = Instance.new("Folder",workspace)
                    console.name = "Console"
                    print("Console Made")
                elseif msg == "Console off" then
                    print("Console Destroyed")
                    console:Destroy()
                end
            end)

您需要在末尾添加另一个end)以关闭game.Players.PlayerAdded:Connect(function(plr)

game.Players.PlayerAdded:Connect(
    function(plr)
        plr.Chatted:Connect(
            function(msg)
                print("Connected")
                if msg == "Console on" then
                    console = Instance.new("Folder",workspace)
                    console.name = "Console"
                    print("Console Made")
                elseif msg == "Console off" then
                    print("Console Destroyed")
                    console:Destroy()
                end
            end)
    end)