Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to create Money, Kills and Deaths leaderstats?

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!

1 comment

0

do you mean so that there are a intvalue like for the Money?

1 answer

✓ Accepted answer

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

2 comments

1

Tysm!!!

1

I also wanted to say about that issue. I'm bad at reading scripts, the script was made by a friend-rookie

This discussion is preserved as it was. New answers, comments, and votes are closed.