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

Why doesn't this data persistence script work?

I have a script that saves a player's leaderstats for how many kills that player has achieved. Here's the script:

game.Players.PlayerRemoving:connect(function(player)
	local s = player:findFirstChild("leaderstats")
	if s then
		local k = s:findFirstChild("Kills")
		player:SaveNumber("kill", k.Value)
	end
end)

game.Players.PlayerAdded:connect(function(player)
	if player:WaitForDataReady() then
		player:LoadNumber("kill")
	end
end)

The problem is that the script doesn't do anything. I tried putting print("check") in both lines of code and nothing showed up in the output. Any help?

1 answer

✓ Accepted answer

LoadNumber returns a number.

You aren't doing anything with that number. Line 11 is just like setting

math.sqrt(15)

on its own.

Set the value of kills:

player:WaitForChild("leaderstats"):WaitForChild("Kills").Value =
	player:LoadNumber("kill")

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