So i'm working on a game with a point system, and it was able to save data just fine.. but later on it just broke randomly and now it won't save points, and always loads old data.. I'm new on databases and such, so anyone know what's wrong with my script?
local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("******")
local lvl = DataStore:GetDataStore("******")
game.Players.PlayerAdded:connect(function(player)
local leader = Instance.new("Folder",player)
leader.Name = "leaderstats"
local Cash = Instance.new("IntValue",leader)
Cash.Name = "Cash"
Cash.Value = ds:GetAsync(player.UserId) or 0
ds:SetAsync(player.UserId, Cash.Value)
Cash.Changed:connect(function()
ds:SetAsync(player.UserId, Cash.Value)
end)
local Level = Instance.new("IntValue", leader)
Level.Name = "Lvl"
Level.Value = lvl:GetAsync(player.UserId) or 0
lvl:SetAsync(player.UserId, Level.Value)
Level.Changed:connect(function()
lvl:SetAsync(player.UserId, Level.Value)
end)
end)
game.Players.PlayerRemoving:connect(function(player)
ds:SetAsync(player.UserId, player.leaderstats.Cash.Value)
lvl:SetAsync(player.UserId, player.leaderstats.Lvl.Value)
end)

2 comments
I tried your method, but It does the same thing. I believe it's an issue with filtering enabled, because it works while FE is disabled, but otherwise..
Nevermind, I found my problem and fixed it. Thank you for your help though!