Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited 5 years ago

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
0
Don't use a RemoteFunction User#19524 175 — 5y
0
What am i supposed to use then? IwanCodes 8 — 5y

1 answer

Log in to vote
0
Answered by
poke7667 142
5 years ago

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.

Ad

Answer this question