Datastore help please!

Hi everyone! c4tlover here :smile:
I was following a simulator making tutorial by Gamer M8 (the only channel I have found that has working code, check him out, he has heaps of great tutorials!), and I managed to code every concept mainly by myself except from the data store, which I don’t even know how it works. Could you please tell me what I’ve done wrong? It isn’t saving my data, even thought I followed the tutorial very closely.

Thank you :smile:

local DS = game:GetService("DataStoreService"):GetDataStore("SaveData")
game.Players.PlayerAdded:Connect(function(plr)
	wait()
	local plrkey = "id_"..plr.userId
	local save1 = plr.leaderstats.Speed
	local save2 = plr.leaderstats.Coins
	
	local GetSaved = DS:GetAsync(plrkey)
	if GetSaved then
		save1.Value = GetSaved[1]
		save2.Value = GetSaved[2]
		
	else 
		local NumberForSaving = {save1.Value, save2.Value}
		DS:GetAsync(plrkey, NumberForSaving)
				
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	DS.SetAsync("id_"..plr.userId, {plr.leaderstats.Speed.Value, plr.leaderstats.Coins.Value})
	
end)

Change this line

DS.SetAsync("id_"..plr.userId, {plr.leaderstats.Speed.Value, plr.leaderstats.Coins.Value})

to

DS:SetAsync("id_"..plr.userId, {plr.leaderstats.Speed.Value, plr.leaderstats.Coins.Value})
1 Like

If this didn’t work, check this topic.

1 Like

Change plr.userId to plr.UserId (Case sensitive)

2 Likes