the data isn’t saving for this script (what i mean is i have a button that you can click to get “baba”, and then when you rejoins your score is reset to 0, instead of saving to your original score), does anyone have any ideas/ could help me? much appreciated
local dsService = game:GetService("DataStoreService")
local ds = dsService:GetDataStore("babasaves")
game.Players.PlayerAdded:Connect(function(plr)
wait(1)
local folder = plr:FindFirstChild('leaderstats') or Instance.new("Folder", plr)
folder.Name = "leaderstats"
local currency = Instance.new("IntValue", folder)
currency.Name = "baba"
currency.Changed:Connect(function()
ds:SetAsync(plr.UserId, currency.Value)
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
ds:SetAsync(plr.UserId, plr.leaderstats.baba.Value)
end)