Leaderstats bug

Hi! I’m doing something wrong? I can’t figure out what’s happening, everything is going fine until something happens

image

while true do

local players = game.Players:GetChildren()

for i, plr in pairs(players) do
	
	local leaderstats = plr:FindFirstChild("leaderstats")
	
	if leaderstats then
		
		leaderstats:WaitForChild("TotalCoins",1).Value = ab:ab(game.ServerStorage.Data[plr.Name].Coins.Value) 
		leaderstats:WaitForChild("Kills",1).Value = ab:ab(game.ServerStorage.Data[plr.Name].Kills.Value) 
		
	end
	
end

wait(0.5)

end

Could you explain what the problem is specifically?

As you can see in the image, some data is not shown. Everythings fine for hours, and then something happens

Are these values stored in Data Stores. There can be another factor causing this issue other than this script.

Have you tried printing the leader stat values? To see if it returns nil?

It’s complicated because this works fine for a while, like hours. And then it fails

while true do

local players = game.Players:GetPlayers()

for i, plr in pairs(players) do
	
	local leaderstats = plr:WaitForChild("leaderstats")
	
	if leaderstats then
		
		leaderstats:WaitForChild("TotalCoins").Value = ab:ab(game.ServerStorage.Data[plr.Name].Coins.Value) 
		leaderstats:WaitForChild("Kills").Value = ab:ab(game.ServerStorage.Data[plr.Name].Kills.Value) 
		
	end
	
end

wait(0.5)
end

You shouldn’t be using “GetChildren” for players, and you shoudl be using waitforchild with leaderstats. If the server is running for a long time, it may not see those instances immedaitly.

1 Like

I think, you are incrementing leaderstat data on a LocalScript, so it doesn’t show on the server.

Its on a serverscript in server script service