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)
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
game.Player.PlayerRemoving:Connect(function(player) local key = "Player_"..player.UserId DataStore:SetAsync(key,{ 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 end -- and on line 24 put "Value" word Spirit.Value = savedvalues[2]