Cant DataStore (15 char)

I cant seem to make the datastore script work.Heres my script(No output)

local DS = game:GetService("DataStoreService"):GetDataStore("SaveData")

game.Players.PlayerAdded:Connect(function(plr)
	wait()
	local plrkey = "id_"..plr.userId
	local save1 = plr.leaderstats.Knowledge
	local save2 = plr.leaderstats.Cash
	
	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.Knowledge.Value,plr.leaderstats.Cash.Value})
end)

anything i can do to make it work?

Did you mean to use SetAsync here?

1 Like

In your code you try and get their data, when it doesn’t get it, you’re using DS:GetAsync*plrkey, NumberForSaving) instead of DS:SetAsync();

Whats the difference? (30 charrr)

DataStore:GetAsync(Key) is used to get data pertaining to the key provided.
Where as
DataStore:SetAsync(Key, Data) is used to set data with the key provided.

Wiki: GlobalDataStore | Documentation - Roblox Creator Hub
GetAsync: GlobalDataStore | Documentation - Roblox Creator Hub
SetAsync: GlobalDataStore | Documentation - Roblox Creator Hub

oh thanks! (30 charrrrrrrrrrrrr)

To get past the 30 character limit you can do an HTML comment <!-- 30 chars –>

It worked!! Thanks btw