roblox工作室'结束'预计(在第1行关闭'功能')附近

问题描述 投票:0回答:1

我试图编写一些代码来创建一个名为Console inside Folder的文件夹,当有人聊天时“Console on”并在有人说“Console off”时将其删除但是当我在公共游戏中运行时(因为在roblox中没有聊天)工作室的测试模式)我得到标题错误,阅读几个帖子后都没有答案。

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)
lua roblox
1个回答
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)
© www.soinside.com 2019 - 2024. All rights reserved.