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

Saving String Values in Data Store?

Asked by 4 years ago

Hello,

I was trying to save 2 string values parented inside of the player, But I have some issues:

  • the first String Value is called "desk1" -the second String Value is called "desk2"

so when I get into the game, If desk1.Value and desk2.Value is changed it shows that It got saved but when I rejoin, it still the same.

Script:

local DS = game:GetService("DataStoreService"):GetDataStore("rubyigergetgseddendikzakinchepes")
game.Players.PlayerAdded:Connect(function(plr)
    wait(2)
    local plrkey = "id_"..plr.userId

    local savevalue1 = plr.leaderstats.Money
    local savevalue2 = plr.workspaces0
    local savevalue3 = plr.desk1
    local savevalue4 = plr.desk2

    local GetSaved = DS:GetAsync(plrkey)
    if GetSaved then
print(GetSaved[5])

        savevalue1.Value = GetSaved[1] or 10000
        savevalue2.Value = GetSaved[2] or 0
        savevalue4.Value = GetSaved[5]  or "none"

        savevalue3.Value = GetSaved[3] or "none"

    else
        local NumbersForSaving = { savevalue1.Value or 10000, savevalue2.Value,savevalue4.Value, savevalue3.Value}
        DS:GetAsync(plrkey, NumbersForSaving)
    end

        savevalue1.Changed:Connect(function(changed) DS:SetAsync("id"..plr.userId, {plr.leaderstats.Money.Value})  print("Changed Money") end)
        savevalue2.Changed:Connect(function(changed) DS:SetAsync("id"..plr.userId, {plr.workspaces0.Value})  print("Changed workspaces") end)
        savevalue3.Changed:Connect(function(changed) DS:SetAsync("id"..plr.userId, {plr.desk1.Value})  print("Changed desk1") end)
        savevalue4.Changed:Connect(function(changed) DS:SetAsync("id"..plr.userId, {plr.desk2.Value})  print("Changed desk2") end)

end)
game.Players.PlayerRemoving:Connect(function(player)

DS:SetAsync("id"..player.userId, {player.desk2.Value}) print("saved")
end)

I don't see any errors in the output, But when the values change, They get saved cuz I did does print() inside of the script, So I can see it in the output

Answer this question