Roblox Studio Lua: 制作一个击杀奖励脚本

我正在开发一个 Roblox 游戏,这是一个战斗游戏。我想制作一个击杀奖励脚本,也就是说每个杀敌者可以获得 +10 的金币,你一开始没有金币。排行榜上的名字应该是“Cash”。有人能帮我写一个这样的脚本吗?我在网上找过很多,希望你们能帮助我。请在脚本中包含“Cash”排行榜。提前感谢!

更新 我已经包含了脚本的代码,但是它不是给予我金币,而是给予被杀者金币。我该如何修复这个问题?

这是代码:

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)
点赞
用户5831152
用户5831152

如果你没有编写脚本的经验,这就是一个有点复杂的任务。这需要你的武器系统去追踪谁杀了谁,并将其提供给排行榜。

如果你使用默认的 Roblox 武器,这个功能很可能已经在你的武器中了。如果你正在制作定制武器,则需要自己实现。

我建议你查看 Roblox Wiki 中的一篇关于排行榜的示例。这是一篇与排行榜有关的相关文章。此外,在工具箱中还有很多排行榜可供你根据需要进行编辑。在排行榜的“Roblox Sets”部分中找到的默认排行榜在击杀时(使用默认的 Roblox 武器)会增加名为“Kills”的计数器,你可以将其编辑为增加现金。然而,这也取决于你如何追踪你的杀敌数。

下一次,请提供代码和/或更详细的描述,说明你已经尝试了什么,这样我们就可以更容易地帮助你理解或指导你。现在看起来你似乎没有真正自己搜索过,而是直接在这里发布了你的问题。

2018-06-17 10:51:03
用户2616735
用户2616735

你增加了currency1中的金额。但currency1属于player,他已经死亡了!

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

....
if tag ~= nil then
    local killer = tag.Value
    if killer ~= nil then
        -- 寻找杀手的leaderstats文件夹
        local killerStats = killer:FindFirstChild("leaderstats")

        if killerStats ~= nil then
            -- 寻找杀手的Cash IntValue
            local killerCash = killerStats:FindFirstChild("Cash")

            -- 如前所述增加现金
            killerCash.Value = killerCash.Value + 10
        end
   end
end
......
2018-06-22 03:25:31