Here is the script I used to script my currency that saves.
--Datastore service local DSS = game:GetService("DataStoreService") local Money = DSS:GetDataStore("Cash") game.Players.PlayerAdded:Connect(function(plr) local pCash = Money:GetAsync(plr.UserId)or 10 local leaderstats = Instance.new("Folder",plr) leaderstats.Name = "leaderstats" local CashValue = Instance.new("NumberValue") CashValue.Name = "Cash" CashValue.Value = pCash CashValue.Parent = leaderstats CashValue.Changed:connect(function(v) Money:SetAsync(plr.UserId,v) print("MoneySaved!") end) end)
your code is very unclear i have made a better version for you.
local DataStoreService = game:GetService("DataStoreService") local Money = DataStoreService:GetDataStore("Cash") function playeradded(plr) local leaderstats = Instance.new("Folder") leaderstats.Parent = plr leaderstats.Name = "leaderstats" local Cash = Instance.new("NumberValue") Cash.Name = "Cash" Cash.Value = Money:GetAsync(plr.UserId) or 10 Cash.Parent = leaderstats end function plrremoving(plr) Money:SetAsync(plr.UserId, plr.leaderstats.Cash.Value) end game.Players.PlayerAdded:Connect(playeradded) game.Players.PlayerRemoving:Connect(plrremoving)
If this still don't work check if you have Api acces via studio enabled.