首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Roblox Lua:为杀死脚本创造现金

Roblox Lua:为杀死脚本创造现金
EN

Stack Overflow用户
提问于 2018-06-17 11:58:55
回答 2查看 5.2K关注 0票数 0

所以,我正在制作一个Roblox游戏,这是一个战斗游戏。我想做一个现金换杀死脚本,意思是每杀一次,杀手得到+10现金,而你一开始只有0现金。排行榜上的名字应该是Cash。有没有人能帮我写个脚本?我在网上什么都试过了,希望你们能帮上忙。请在脚本中包含排行榜现金。提前感谢!

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

代码如下:

代码语言:javascript
复制
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)
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-06-22 11:25:31

你在currency1中增加了钱的数量。但是currency1是属于player的,谁拥有.Died

假设creator是一个ObjectValue,它的值是杀手的Player实例,我们可以增加该player的"Cash“:

代码语言:javascript
复制
....
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
......
票数 0
EN

Stack Overflow用户

发布于 2018-06-17 18:51:03

如果您没有使用脚本的经验,这是一项有点复杂的任务。这需要你的武器系统来跟踪谁杀了人,并将其输入排行榜。如果你使用默认的罗伯克斯武器,这个功能很可能已经在你的武器中了。如果你正在制作定制的武器,你需要自己实现它。

我建议你去看看Roblox,看看排行榜的例子。This is a relevant article about Leaderboards。工具箱中也会有大量的排行榜,您可以根据需要进行编辑。默认的排行榜在排行榜的“罗布洛克斯集”部分增加了一个名为“杀死”的计数器(使用默认的罗布洛克斯武器),你可以编辑它来增加现金。然而--再说一次--取决于你如何记录你的猎物。

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50893551

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档