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

Leaderstat not showing when played?

I tried making a level leaderstat, but it does not show when I play. Here Is the code.

game.Players.PlayerAdded:connect(function(player)
local DataStore = game:GetService("DataStoreService")

	 local leader = Instance.new("Folder",player)
leader.Name = "leaderstats"

for i,v in pairs(script:GetChildren()) do 
local d = DataStore:GetDataStore(v.Name)
local x = Instance.new("NumberValue",leader)
x.Name = v.Name
x.Value = d:GetAsync(player.UserId) or v.Value



end
end)

game.Players.PlayerRemoving:Connect(function(player)
	for i,v in pairs(script:GetChildren()) do 
		print("Getting")
		local DataStore = game:GetService("DataStoreService")
		local d = DataStore:GetDataStore(v.Name)
		d:SetAsync(player.UserId, player.leaderstats[v.Name].Value)
		print("Saved")
	end
end)

1 answer

✓ Accepted answer

That was because you didn't actually create an IntValue . IntValues are basically a value which you can store numbers. Such as stats etc To learn more about Leaderstats visit: https://developer.roblox.com/en-us/articles/Leaderboards

The leaderboard script should be

game.Players.PlayerAdded:Connect(function(plr)
	local stats = Instance.new("Folder",plr)
	stats.Name = "leaderstats"
	
	local money = Instance.new("IntValue",stats) -- you can change money to whatever you want
	money.Name = "Money"
	money.Value = 0
end)


game.Players.PlayerAdded:connect(function(player)
local DataStore = game:GetService("DataStoreService")

     

for i,v in pairs(game.Players.PlayerAdded:GetChildren()) do 
local d = DataStore:GetDataStore(v.Name)
local x = Instance.new("NumberValue",stats)
x.Name = v.Name
x.Value = d:GetAsync(player.UserId) or v.Value



end
end)

game.Players.PlayerRemoving:Connect(function(player)
    for i,v in pairs(script:GetChildren()) do 
        print("Getting")
        local DataStore = game:GetService("DataStoreService")
        local d = DataStore:GetDataStore(v.Name)
        d:SetAsync(player.UserId, player.leaderstats[v.Name].Value)
        print("Saved")
    end
end)

9 comments

0

Last time you call money you use capitalised M

0

It still does not show it when I play test it

0

I edited it. It should work now just copy the scripts

0

If this answer helped please accept my answer

0

it still does not show it for some reason

0

Is it in the local script

0

if so then put it in the Server script

0

no, it still does not work. Hmmm is it because of the new place that shows the players name?

0

I think I know why it didnt work

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