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

my leaderstats datastore isnt working.. how do i fix it?

my data doesnt save when i rejoin

this is in a seperate script from the leaderstats

local datastore = game:GetService("DataStoreService"):GetDataStore("SavaData")
game.Players.PlayerAdded:Connect(function(plr)
	wait()
	local plrid = "id_"..plr.UserId
	local save1 = plr.leaderstats.Coins
	
	local GetSaved = datastore:GetAsync(plrid)
	if GetSaved then
		save1.Value = GetSaved[1]
		
	else
		local NumberForSaving = {save1.Value}
		datastore:GetAsync(plrid, NumberForSaving)
		
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	datastore:SetAsync("id_"..plr.UserId{plr.leaderstats.Coins.Value})
end)

1 comment

0

anyone helping me out? its been 11 hours and i need this bad

1 answer

I believe that your data isn't saving because the server shuts down before SetAsync() can be called (assuming you are the only person testing). Try using game:BindToClose() so that the server gives itself time to save everything before it shuts down completely.

For example:

game:BindToClose(function()
	--here you would loop through all players and save their data
end)

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