【问题标题】:roblox studio 'end' expected (to close 'function' at line 1) near <eof>roblox studio 'end' 预计在 <eof> 附近(在第 1 行关闭 'function')
【发布时间】:2019-07-22 16:40:45
【问题描述】:

我尝试编写一些代码以在有人聊天“控制台打开”时在工作区中创建一个名为控制台的文件夹,并在有人说“控制台关闭”时删除它但是当我在公共游戏中运行它时(因为没有在 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)

【问题讨论】:

  • 您打开两个函数和一个 (else)if 但只有两个 ends。

标签: lua roblox


【解决方案1】:

如果代码缩进更一致,就会更容易看出语法错误在哪里:

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)

【讨论】:

    猜你喜欢
    • 2014-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-07
    • 2016-06-27
    • 1970-01-01
    • 2015-08-19
    相关资源
    最近更新 更多