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

Little help with my Leader Stats code?

Hello guys, I just wrote a leaderstats code and it enters IntValue into player but it isn't showing up on leaderstats. It also won't show any error...anyone can help me?

game.Players.PlayerAdded:connect(function(player)
	local stats = Instance.new('IntValue', player)
	stats.Name = 'LeaderStats'
	local cash=Instance.new('IntValue',stats)
	cash.Name = 'Cash'
	cash.Value = 0
	local rank=Instance.new('StringValue', stats)
	rank.Name='Rank'
	rank.Value='Private'
end)

2 answers

✓ Accepted answer

The 'leaderstats' object is case sensitive and should be named with all lowercase letters. It is also advised for the object to be a folder or model as there is a chance it won't work if you use a Value object.

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

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

    -- which ever other stats you want
end)

1 comment

0

Thanks man!

The object must be named leaderstats with only lowercase letters. I added the line to get the user's role from a groupid you need to enter.

game.Players.PlayerAdded:connect(function(player)
	Instance.new("Folder", player).Name = "leaderstats"
	Instance.new("NumberValue", player).Name = "Cash"
	Instance.new("StringValue", player).Name = "Rank"
	
	player.leaderstats.Rank.Value = player:GetRoleInGroup(0)
end)

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