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

My leaderstats don't show up. How do I fix this?

So, I'm trying to make leaderstats. I've followed a lot of tutorials, this is what i have.

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

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

	score.Parent = stats	
	stats.Parent = newPlayer
end

game.Players.ChildAdded:connect(onPlayerEntered)

It doesn't work. How do I make one that works?

1 answer

✓ Accepted answer

This script also will save the currency of your cash, you also have to place this script in the ServerScriptService

local ds = game:GetService("DataStoreService"):GetDataStore("--Cash01")

game.Players.PlayerAdded:Connect(function(player)
	local folder = Instance.new("Folder",player)
	folder.Name = "leaderstats"
	local cash = Instance.new("IntValue",folder)
	cash.Name = "Cash"
	cash.Value = 20

	local key = "cash-"..player.userId

	local save = ds:GetAsync(key)
	if save then
		cash.Value = save
	end
	cash.Changed:Connect(function()
		ds:SetAsync(key,cash.Value)
	end)	
end)

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