The title basicly explains it all.
My datastore isn't working correctly. I have no idea why.
Here is my datastore script.
local DSService = game:GetService('DataStoreService'):GetDataStore('Leaderstats2')
game.Players.PlayerAdded:Connect(function(plr)
-- Define variables
local uniquekey = 'id-'..plr.userId
local leaderstats = Instance.new('IntValue', plr)
leaderstats.Name = 'leaderstats'
local savevalue = Instance.new('IntValue')
savevalue.Parent = leaderstats
savevalue.Name = 'Money'
savevalue.Value = '500'
local savevalue2 = Instance.new('IntValue')
savevalue2.Parent = leaderstats
savevalue2.Name = 'Gems'
-- GetAsync
local GetSaved = DSService:GetAsync(uniquekey)
if GetSaved then
savevalue.Value = GetSaved[1]
savevalue2.Value = GetSaved[2]
else
local NumbersForSaving = {savevalue.Value, savevalue2.Value}
DSService:SetAsync(uniquekey, NumbersForSaving)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local uniquekey = 'id-'..plr.userId
local Savetable = {plr.leaderstats.Money.Value, plr.leaderstats.Gems.Value}
DSService:SetAsync(uniquekey, Savetable)
end)
It's in a script in serverscripts.
It works correctly, but when you leave and join back none of the data is saved. It's the exact same data script as my other game, but it works on my other game perfectly.
Also when I print my datastore in developer console.
The value it shows 0.
I know that it has changed.
AND YES I DO KNOW THAT IN THAT IMAGE A PRINT A DIFFERENT DATA STORE!!!
The same thing happens for the money.

3 comments
Thanks. Doesn't work, but thats for helping!
Please try the edited revision, i added a pcall so that it will determine if an error is thrown and removed a redundant section
@kittonlover101 does it works in game and not in studio ? if yes then you should use :Kick() on yourself so the playerremoving event will fire