Data doesnt save

the data isn’t saving for this script (what i mean is i have a button that you can click to get “baba”, and then when you rejoins your score is reset to 0, instead of saving to your original score), does anyone have any ideas/ could help me? much appreciated :smiley:

local dsService = game:GetService("DataStoreService")
local ds = dsService:GetDataStore("babasaves") 



game.Players.PlayerAdded:Connect(function(plr)
	wait(1)
	local folder = plr:FindFirstChild('leaderstats') or Instance.new("Folder", plr)
	folder.Name = "leaderstats"
	local currency = Instance.new("IntValue", folder)
	currency.Name = "baba" 
	currency.Changed:Connect(function()
		ds:SetAsync(plr.UserId, currency.Value)
	end)
end)


game.Players.PlayerRemoving:Connect(function(plr)
	ds:SetAsync(plr.UserId, plr.leaderstats.baba.Value) 
end)

1 Like

You probably aren’t changing the value of baba on the server. If you change its value on the client, the change won’t replicate to the server.

4 Likes

That is very inefficient and will cause throttling.
Read more about DataStore Limits/Errors here.

I recommend DataStore2.

If you go into community resources, you should be able to search for datastore 2, and you can download a .rbxm file to just drag into workspace that should save automatically.