I watched tons of datastore videos and see NOTHING wrong with my code
local DSService = game:GetService("DataStoreService"):GetDataStore("Currency")
game:GetService("Players").PlayerAdded:connect(function(plr)
local leader = Instance.new("Folder",plr)
leader.Name = "leaderstats"
local Credits = Instance.new("IntValue",leader)
Credits.Name = "Credits"
local Diamonds = Instance.new("IntValue",leader)
Diamonds.Name = "Diamonds"
local key = "player-"..plr.UserId
local savedData = DSService:GetAsync(key)
if savedData then
Credits.Value = savedData[1]
Diamonds.Value = savedData[2]
else
local values = {Credits.Value, Diamonds.Value}
DSService:SetAsync(key,values)
end
end)
game:GetService("Players").PlayerRemoving:connect(function(plr)
local ValuesToSave = {plr.leaderstats.Credits.Value, plr.leaderstats.Diamonds.Value}
DSService:SetAsync(plr.UserId, ValuesToSave)
end)
while wait(300) do
for i,v in pairs(game:GetService("Players"):GetChildren()) do
local key = v.UserId
DSService:SetAsync(key,v.leaderstats.Credits.Value,v.leaderstats.Diamonds.Value)
end
end

1 comment
Aren't you supposed to parent those to the player?