user8891469
user8891469

Reputation:

Roblox Studio Lua: Making A Cash For Kill Script

So, I am making a Roblox game and it's a battle game. I want to make a cash for kill script, meaning every kill, the KILLER gets +10 cash, and you start off with 0 cash. The name on the leaderboard should be Cash. Can someone please make a script for this? I've tried everything on the web, so I hope you guys can help. Please include the leaderboard Cash in the script. Thanks in advance!

Update I've included the code for the script, but instead of giving me the cash, it gives the killed person cash. How can I fix this?

Here is the code:

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)

Upvotes: 0

Views: 8070

Answers (2)

Curtis Fenner
Curtis Fenner

Reputation: 1411

You increase the amount of money in currency1. But currency1 belongs to player, who is the who has .Died!

Assuming creator is an ObjectValue whose Value is the Player instance of the killer, we can get that player's "Cash" to increase:

....
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
......

Upvotes: 0

Ravenshield
Ravenshield

Reputation: 133

This is a bit of a complex task if you have no experience with scripting. This requires your weapon system to keep track of who kills, and feed that into the leaderboard. If you use default Roblox weapons, this functionality is likely already in your weapons. If you are making custom weapons, you need to implement this yourself.

I suggest you check out the Roblox Wiki for an example of Leaderboards. This is a relevant article about Leaderboards. There are also going to be plenty of leaderboards in the Toolbox that you can edit to your needs. The default Leaderboard found in the "Roblox Sets" section of the Leaderboard increases a counter named "Kills" upon kills (with default Roblox weapons), and you can edit this to increase Cash instead. However - again - depends on how you keep track of your kills.

Next time please provide code and/or more detailed description of what you have already tried, so it is easier for us to help you understand or give you pointers. Right now it looks like you haven't really searched on your own and just posted your question here right away.

Upvotes: 0

Related Questions