【问题标题】:How to fix an end expected error near eof如何修复 eof 附近的预期结束错误
【发布时间】:2020-02-16 23:35:03
【问题描述】:

我在 Roblox 中制作了杀戮脚本的现金,但想更进一步并实现一个脚本,当玩家拥有游戏通行证时,该玩家将获得比其他普通玩家更多的现金。

这是 Roblox 中一款大逃杀风格的游戏,当我进行游戏测试时,没有错误,但脚本无法运行。

game.Players.PlayerAdded:connect(function(player)
    local folder = Instance.new("Folder",player)
    folder.Name = "leaderstats"
    local currency1 = Instance.new("IntValue",folder)
    currency1.Name = "Cash"

    local increment = 50

    if game:GetService("MarketplaceService"):PlayerOwnsAsset(player,7382818)then 
        increment = increment + 50
    end

    player:WaitForChild("Humanoid").Died:connect(function()
        local tag = player.Humanoid:FindFirstChild("creator")
        if tag ~= nil then
            local killer = tag.Value
            if killer ~= nil then
                -- Find the killer's leaderstats folder
                local killerStats = killer:FindFirstChild("leaderstats")

                if killerStats ~= nil then
                    -- Find the killer's Cash IntValue
                    local killerCash = killerStats:FindFirstChild("Cash")

                    -- Increase cash as before
                    killerCash.Value = killerCash.Value + increment
                end
            end
        end
    end)

我预计拥有游戏通行证的 VIP 玩家会收到更多现金,但当我测试它时,根本没有玩家因杀死其他玩家而收到任何现金。

【问题讨论】:

  • 你没有关闭外部(或内部)函数
  • 你用end)关闭player:WaitForChild("Humanoid").Died:connect(function(),但你没有用end)关闭game.Players.PlayerAdded:connect(function(player)

标签: lua roblox


【解决方案1】:

如何修复 eof 附近的预期结束错误

如果 Lua 解释器抱怨缺少 end,那么你在某处丢失了它。

通读您的代码并确保所有应该用end 关闭的东西都有一个。通读 Lua 参考手册,找出哪些关键字需要end

在您的代码中是 if 语句和函数定义。从里到外检查每一对,你最终会得到一个 end) 短来关闭这个 game.Players.PlayerAdded:connect(function(player),如 cmets 中所述。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-04
    • 1970-01-01
    • 2016-05-07
    相关资源
    最近更新 更多