Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to create Money, Kills and Deaths leaderstats?

Asked by 3 years ago

I also wanted to increase cash by 100 to the killer after each kill. Here is the script I used:

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

 local currency1 = Instance.new("IntValue",leaderstats)
 currency1.Name = "Money"
 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 + 100 --This is the reward after the player died.
         end
       end
     end)
   end)
 end)

Could you please add Kills and Deaths to that script? Tysm!

0
do you mean so that there are a intvalue like for the Money? itzstarboss 9 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Bit confused but hopefully this answers your question

Why don't you just add 2 other intvalues, name it "Deaths" and "Kills" then everytime a player dies or kills someone you add onto it? And also, you want 100 to go to the killer, but in your script you are giving 100 to the player that died

edited version of your script:

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

    local currency1 = Instance.new("IntValue",leaderstats)
    currency1.Name = "Money"

    local deaths = Instance.new("IntValue",leaderstats) -- your new death value
    deaths.Name = "Deaths"

    local kills = Instance.new("IntValue",leaderstats) -- new kills value
    kills.Name = "Kills"
    player.CharacterAdded:connect(function(character)
        character:WaitForChild("Humanoid").Died:Connect(function()
            local tag = character.Humanoid:FindFirstChild("creator")
            if tag.Value ~= nil then -- also, you added another line of this. why? its useless since you already checked here
                local killer = game.Players[tag.Value] -- GET THE KILLER TO ADD, NOT THE PLAYER WHO DIED
                killer.leaderstats.Money.Value = killer.leaderstats.Money.Value + 100 -- reward killer
                killer.leaderstats.Kills.Value = killer.leaderstats.Kills.Value + 1 -- add a kill to the killer
                player.leaderstats.Deaths.Value = player.leaderstats.Deaths.Value + 1 -- add a death to the person that died (you already identified, player from playeradded)      
            end
        end)
    end)
end)

hope that helps

1
Tysm!!! nikitos54327 70 — 3y
1
I also wanted to say about that issue. I'm bad at reading scripts, the script was made by a friend-rookie nikitos54327 70 — 3y
Ad

Answer this question