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 = Instance.new("IntValue", player)
stats.Name = "leaderstats"
local SpiritClass = Instance.new("StringValue", stats)
SpiritClass.Name = "SpiritClass"
SpiritClass.Value = "E"
local Spirit = Instance.new("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)

5 comments
So I say valuesToSave = {player.leaderstats.SpiritClass.Value; player.leaderstats.Spirit.Value;} ?
Yes but only thing that you need to make info like a list
Thank you!
The way this is being saved is correct. Both ; and , are valid for a list.
The error was not using.Value on line 24