Still have questions? Join our Discord server and get real time help.
Log in to vote

DataStore service not saving?

Asked by 5 months ago

Hello I'm learning how to make data stores and made one. However it is giving me issues that aren't displayed in the output so I don't know what is causing the issue.

I have a leader board with 2 stats one is an int value and the other is a string value. I have a part that gives me points to the int value and I want this data store to save the newly added points when I leave the game so that if I returned to the game the points will still be there. However when I tested it, the points are not saved and displayed as 0 (Original amount).

This is my script.

local DataStore = game:GetService("DataStoreService"):GetDataStore("Strength") game.Players.PlayerAdded:Connect(function (player) local stats ="IntValue", player) stats.Name = "leaderstats" local SpiritClass ="StringValue", stats) SpiritClass.Name = "SpiritClass" SpiritClass.Value = "E" local Spirit ="IntValue", stats) Spirit.Name = "Spirit" local key = "Player_"..player.UserId local savedvalues = DataStore:GetAsync(key) if savedvalues then -- if the player has played before then it'll load there stats -- format of saving is {SpiritClass, SpiritStrength} SpiritClass.Value = savedvalues[1] Spirit = savedvalues[2] else local valuesToSave = {SpiritClass.Value, Spirit.Value} DataStore:SetAsync(key, valuesToSave) end end) game.Players.PlayerRemoving:Connect(function (player) local key = "Player_"..player.UserId --save key: {Spiritclass, Spirit} local valuesToSave = {player.leaderstats.SpiritClass.Value, player.leaderstats.Spirit.Value} DataStore:SetAsync(key, valuesToSave) end)

1 answer

Log in to vote
Answered by
HaveASip 494 Moderation Voter
5 months ago
Edited 5 months ago

All your script is right, but you have two errors. Both errors about saving data. If you want to save multiple data you need to save it like this

    local key = "Player_"..player.UserId

        player.leaderstats.SpiritClass.Value; -- This is a first one
        player.leaderstats.Spirit.Value; --Second
    --and if you saving multiple data you need to put ";" this before typing next
    --that means you have another info

-- and on line 24 put "Value" word
Spirit.Value = savedvalues[2]
So I say valuesToSave = {player.leaderstats.SpiritClass.Value; player.leaderstats.Spirit.Value;} ? veileno 7 — 5mo
Yes but only thing that you need to make info like a list HaveASip 494 — 5mo
Thank you! veileno 7 — 5mo
The way this is being saved is correct. Both ; and ,  are valid for a list. kingdom5 5294 — 5mo
The error was not using.Value on line 24 kingdom5 5294 — 5mo

Answer this question