【问题标题】:Roblox Studio Lua: Making A Cash For Kill ScriptRoblox Studio Lua:为杀戮脚本赚钱
【发布时间】:2018-11-26 08:38:38
【问题描述】:

所以,我正在制作一款 Roblox 游戏,它是一款战斗游戏。我想为杀戮脚本赚取现金,这意味着每次杀戮,杀手获得+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)

【问题讨论】:

  • 很抱歉让你们所有人都感到困惑。我会记下这个问题。顺便说一句,我只有 10 岁
  • 别担心,下次尝试在您的帖子中发布一些代码:)

标签: lua roblox


【解决方案1】:

您增加了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
......

【讨论】:

  • 另外,如果可以的话,能否请您包含整个脚本?如果你不能完全没问题,我会想办法的。
【解决方案2】:

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

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

下次请提供您已经尝试过的代码和/或更详细的描述,以便我们更容易帮助您理解或给您指点。现在看来你还没有真正自己搜索过,只是马上在这里发布了你的问题。

【讨论】:

    猜你喜欢
    • 2018-12-01
    • 2020-10-17
    • 2019-10-15
    • 2020-07-02
    • 2016-03-31
    • 1970-01-01
    • 2022-10-20
    • 2022-07-12
    • 2020-06-23
    相关资源
    最近更新 更多