Issue with saving player's leaderstats

  1. What do you want to achieve? Keep it simple and clear!
    Saving the player leaderstats
  2. What is the issue? Include screenshots / videos if possible!
    The game errors with: Tocoins is not a valid member of Folder “Stilyan_123.leaderstats”
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve had no solutions and yes, I’ve looked for any, didn’t find what I was looking for
Players.PlayerRemoving:Connect(function(plr)
	Data:SetAsync(
		tostring(plr.UserId), 
		{
			["Tocoins"] = plr.leaderstats.Tocoins.Value, 
			["Topoints"] = plr.leaderstats.Topoints.Value
		}
	)
end)

^ Everything is defined, don’t worry

This means that your leaderstats folder in the Player instance does not have a child called “Tocoins”

Play the game in studio, open your player folder, and check whether it exists under leaderstats. If not, it needs to do so (because that is what you are trying to save). Roblox Studio is trying to tell you that the “Tocoins” you are trying to access simply does not exist.

Ok I see the issue, Tocoins does not exist but it gets replaced by Topoints in this code when the player joins the game

	local tocoins = Instance.new("NumberValue")
	tocoins.Name = "Tocoins"
	tocoins.Parent = leaderstats

	local topoints = Instance.new("NumberValue")
	tocoins.Name = "Topoints"
	tocoins.Parent = leaderstats

EDIT: I see my issue how could I be so blind? Anyways, its because im setting tocoins’ name to Topoints and making it again to leaderstats which breaks it

Yes. Seems to be a typo—when you create topoints as a new Instance, you then go on to re-assign the Name and Parent properties of tocoins. This is likely because you copy-pasted this, but did not change the other two.

Simple issue, but hard to spot!

The script editor (should have) has a feature where if you select a word, all other occurrences of that word highlight. This may help you in the future!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.