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

Saving data and reloading it using Data Stores when I rejoin does not work, why?

Here are the 2 pieces of code:

local dsservice = game:GetService("DataStoreService"):GetDataStore("atcunleashed898")
game.Players.PlayerAdded:Connect(function(plr)
	local uniquekey = "id-"..plr.UserId
	local money = game.ReplicatedStorage:WaitForChild("getmoney"):InvokeClient(plr)
	local getsaved = dsservice:GetAsync(uniquekey)
	print(money)
	local numbersforsaving = {money}
	dsservice:SetAsync(uniquekey,money,numbersforsaving)
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local moneyvalue = game.ReplicatedStorage.getmoney:InvokeClient(plr)
	print(moneyvalue)
	local uniquekey = "id-"..plr.UserId
	local savetable = {moneyvalue}
	dsservice:SetAsync(uniquekey,moneyvalue,savetable)
end)
function getMoney()
	script.Parent:WaitForChild("backdrop"):WaitForChild("money")
	return script.Parent.backdrop.money.Value
end

game.ReplicatedStorage.getmoney.OnClientInvoke = getMoney

2 comments

0

Don't use a RemoteFunction

0

What am i supposed to use then?

1 answer

Make sure the 2nd script is in a localscript. Also, SetAsync only takes 2 arguments (the unique key and the value stored) and you have provided 3. Also, I don't think the server to client communication is needed unless the value is under PlayerGui. Also, you are never setting the value of the money from the DataStore in your script.

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