Hi, I've been wondering why none of my leaderstats would save anything. I've tried multiple scripts, taken lots from different YouTube videos, lots of websites, and many models. Still doesn't work. Yes, I have enabled studio access to API services! The script is in the folder "ServerScriptService"
Here is the script:
(Taken from this video: https://www.youtube.com/watch?v=lS20iM7iRQE&t) (I was going to change "Gems" and "Cash" to kills, and deaths, but this didn't work first..)
`local datastore = game:GetService("DataStoreService") local ds1 = datastore:GetDataStore("GemSaveSystem") local ds2 = datastore:GetDataStore("CashSaveSystem")
game.Players.PlayerAdded:connect(function(plr) local folder = Instance.new("Folder", plr) folder.Name = "leaderstats" local gems = Instance.new("IntValue", folder) gems.Name = "Gems" local cash = Instance.new("IntValue", folder) cash.Name = "Cash"
gems.Value = ds1:GetAsync(plr.UserId) or 0 ds1:SetAsync(plr.UserId, gems.Value)
cash.Value = ds2:GetAsync(plr.UserId) or 0 ds2:SetAsync(plr.UserId, cash.Value)
gems.Changed:connect(function() ds1:SetAsync(plr.UserId, gems.Value) end)
cash.Changed:connect(function() ds2:SetAsync(plr.UserId, cash.Value) end) end) `

5 comments
Would be easier to read the code if you put it inside of a code block.
Done. Its possible it didn't place correctly as I'm currently using mobile.
Hmmm... I dunno, it doesn't want to work..
That script save only not load.
Ah, I see, thanks.