So I'm trying to make a script that makes two leaderstats, Coins, and Level, but the problem that keeps happening is when the coins is changed, lets say the coins value was changed to 100. Then once I rejoin and the datastore saves my progress, it changes Level to the same amount as the coins, so basically the coins are 100, and the level is 100. Heres my code:
local dsService = game:GetService("DataStoreService") local ds = dsService:GetDataStore("MondStats") game.Players.PlayerAdded:Connect(function(plr) local folder = Instance.new("Folder", plr) folder.Name = "leaderstats" local currency = Instance.new("IntValue", folder) currency.Name = "Coins" currency.Value = ds:GetAsync(plr.UserId) or 0 currency.Changed:Connect(function() ds:SetAsync(plr.UserId, currency.Value) end) local currency2 = Instance.new("IntValue", folder) currency2.Name = "Level" currency2.Value = ds:GetAsync(plr.UserId) or 0 currency.Changed:Connect(function() ds:SetAsync(plr.UserId, currency.Value) end) currency2.Changed:Connect(function() ds:SetAsync(plr.UserId, currency2.Value) end) end) game.Players.PlayerRemoving:Connect(function(plr) ds:SetAsync(plr.UserId, plr.leaderstats.Coins.Value, plr.leaderstats.Level.Value) end)
I just figured it out! I wasn't creating the Level's own datastore that it could save on. The datastore the level was using was both of the leaderstats' datastores, which made the Coins value overwrite the level.