Roblox Studio Lua:通过杀死脚本赚钱

Roblox Studio Lua: Making A Cash For Kill Script

所以,我正在制作一款 Roblox 游戏,它是一款战斗游戏。我想为杀死脚本赚取现金,这意味着每次杀死,KILLER 都会获得 +10 现金,而你从 0 现金开始。排行榜上的名字应该是现金。有人可以为此制作一个脚本吗?网上的都试过了,希望大家帮帮忙。请在脚本中包含排行榜现金。提前致谢!

更新 我已经包含了脚本的代码,但它没有给我现金,而是给了被杀的人现金。我该如何解决这个问题?

代码如下:

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

    local currency1 = Instance.new("IntValue",folder)
    currency1.Name = "Cash"

    player.CharacterAdded:connect(function(character)
        character:WaitForChild("Humanoid").Died:connect(function()
            local tag = character.Humanoid:FindFirstChild("creator")
            if tag ~= nil then
                if tag.Value ~= nil then
                    currency1.Value = currency1.Value + 10 --This is the reward after the player died.
                end
            end
        end)
    end)
end)

如果您没有编写脚本的经验,这将是一项有点复杂的任务。这需要您的武器系统跟踪谁杀了人,并将其输入排行榜。 如果您使用默认的 Roblox 武器,您的武器中可能已经具备此功能。如果您正在制作定制武器,则需要自己实施。

我建议您查看 Roblox Wiki 以获取排行榜示例。 This is a relevant article about Leaderboards。 工具箱中还将有大量排行榜,您可以根据需要进行编辑。在排行榜的 "Roblox Sets" 部分中找到的默认排行榜会在击杀时增加一个名为 "Kills" 的计数器(使用默认的 Roblox 武器),您可以对其进行编辑以增加现金。然而 - 再次 - 取决于你如何跟踪你的杀戮。

下次请提供代码and/or更详细的描述你已经尝试过的,这样我们更容易帮助你理解或指点。现在看来您并没有真正自行搜索,只是立即在此处发布您的问题。

你增加了 currency1 中的金额。但是currency1属于player,谁有.Died

假设creator是一个ObjectValue,其Value是杀手的Player实例,我们可以得到那个玩家的"Cash"增加:

....
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 + 10
        end
   end
end
......