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

How to add more than 1 stat on leaderstats?

Hi so I am new to this Scripting stuff and I don't know how to add another stat along with one on my leaderstats. Here is what I tried to do,

> function onPlayerEntered(newPlayer)
	wait(.5)
	local stats = Instance.new("IntValue")
	stats.Name = "leaderstats"

	local score = Instance.new("IntValue")

	score.Name = "Sips"
	score.Value = 0

	score.Parent = stats	
	stats.Parent = newPlayer
end
function onPlayerEntered(newPlayer)
	wait(.5)
	local stats = Instance.new("IntValue")
	stats.Name = "leaderstats"

	local score = Instance.new("IntValue")
	
	score.Name = "Cash"
	score.Value = 0

	score.Parent = stats	
	stats.Parent = newPlayer
end

game.Players.ChildAdded:connect(onPlayerEntered)

2 comments

0

Please format your code. It's hard to read so we can't help you. In order to properly format the code, press the little blue button on the top when editing/writing your code.

0

I fixed it can you help now?

2 answers

✓ Accepted answer

The thing that you did is forget to name the variables differently. If you do that, you will only have 1 stat on leaderstats. This is something that would work:

local sips = Instance.new("IntValue")
	 
score.Name = "Sips"
score.Value = 0
	 
score.Parent = stats   
stats.Parent = newPlayer


local cash = Instance.new("IntValue")
 
score.Name = "Cash"
score.Value = 0
	 
score.Parent = stats   
stats.Parent = newPlayer

4 comments

0

Make sure to close your leaderboard with an end.

0

I know, I was just making the part that the person made an error with.

0

Do I add an end at end of live 7 or both?? But thank you very much this will help me with my game.

0

Yes, you should add an end at line 8.

What you have to do is the following code:

game.Players.PlayerAdded:connect(function(p)
	local stats = Instance.new("IntValue")
	stats.Name = "leaderstats"
	stats.Parent = p
	
	local money = Instance.new("IntValue")
	money.Name = "Money" -- Change "Money" to anything you want to name it like "Cash"
	money.Value = 50 -- Change the value to how many you want when the player joins the game
	money.Parent = stats
	
	
	local Whatever = Instance.new("IntValue")
	Whatever.Name = "Whatever" -- Change "Whatever" to anything you want to name it like "Cash"
	Whatever.Value = 50 -- Change the value to how many you want when the player joins the game
	Whatever.Parent = stats
	
end)

1 comment

0

If my code helped you please accept my answer.

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