如何修复‘在文件结尾附近预期结束’的错误

我在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 玩家可以获得更多的金钱,但是当我测试它时,没有任何玩家会因杀害另一个玩家而获得任何金钱。

点赞
用户2858170
用户2858170

如何修复位于文件末尾附近的“期望end”的错误

如果Lua解释器报告缺少end,则您可能会在某个地方遗漏它。

仔细阅读您的代码,并确保所有应该使用end关闭的内容都有一个。阅读Lua参考手册以查找需要end的关键字。

在您的代码中,这些关键字需要关闭if语句和函数定义。从内到外检查每对关键字,您将发现缺少一个end即可关闭这个game.Players.PlayerAdded:connect(function(player),如评论中所述。

2019-10-21 11:42:08