Why leaderstats value dont saving?

Hello everyone!
I tried make save system for leaderstats with tutorial: https://www.youtube.com/watch?v=tUIvZfp1lFg&t=141s
But data script dont working:

local data = game:GetService("DataStoreService"):GetDataStore("SaveData")
game.Players.PlayerAdded:Connect(function(plr)
	wait()
	local plrid = "id_"..plr.UserId
	local save1 = plr.leaderstats["Fool's"]
	local save2 = plr.LocaleId.Multiplier
	local GetSaved = data:GetAsync(plrid)
	if GetSaved then
		save1.Value = GetSaved[1]
		save2.Value = GetSaved[2]
	else
		local nfs = {save1.Value,save2.Value}
		data:GetAsync(plrid,nfs)
	end
end)
game.Players.PlayerRemoving:Connect(function(plr)
	data:SetAsync("id_"..plr.UserId{plr.leaderstats["Fool's"].Value,plr.leaderstats.Multiplier.Value})
end)

And output writing: “ServerScriptService.Scripts.Player.Player2.Data:13: attempt to index nil with ‘Value’” and " ServerScriptService.Scripts.Player.Player2.Data:18: attempt to call a number value".

You are missing a comma between UserId and {

Not sure what is causing the other error though. We need to see where you are creating the leaderstats. If you aren’t creating the leaderstats at all, lmk and I’ll figure something out.

This is leaderstats script:

game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder",plr)
	leaderstats.Name = "leaderstats"
	local coins1 = Instance.new("NumberValue",leaderstats)
	coins1.Name = "Fool's"
	local coins2 = Instance.new("NumberValue",leaderstats)
	coins2.Name = "Multiplier"
end)

But i added comma, and its not worked.

local save2 = plr.LocaleId.Multiplier

The line above is the problematic one.
I think you meant for it to be

local save2 = plr.leaderstats.Multiplier
1 Like
data:GetAsync(plrid,nfs)

should be

data:SetAsync(plrid,nfs)
1 Like

sorry for the sudden answer.
It turns out that it is not saved in the studio, but is saved in the game.

Yea this is mine another mistake, after write data:SetAsync(plrid,nfs) now saving in studio too.
Sorry for my bad english.

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