Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My leaderstats won't save.. Why? I've enabled studio access to API services..

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

0

Would be easier to read the code if you put it inside of a code block.

0

Done. Its possible it didn't place correctly as I'm currently using mobile.

0

Hmmm... I dunno, it doesn't want to work..

0

That script save only not load.

0

Ah, I see, thanks.

2 answers

Your script is working, I copied and pasted it in my game and it worked... you have no problems at all.

1 comment

0

Weird.. Doesn't work for me, any ideas?

If there was anything wrong with it, here's your script that I modified (and tested) to make it look more neat:

local datastore = game:GetService("DataStoreService") 
local ds1 = datastore:GetDataStore("SaveSystem") -- Changed name, change back to "GemSaveSystem" if others were playing your game so their values are accessible 
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", gems.Value)

	cash.Value = ds1:GetAsync(plr.UserId) or 0 ds1:SetAsync(plr.UserId.."-Cash", cash.Value)
	
	gems.Changed:connect(function() 
		ds1:SetAsync(plr.UserId.."-Gems", gems.Value) 
	end)
	
	cash.Changed:connect(function() 
		ds1:SetAsync(plr.UserId.."-Cash", cash.Value) 
	end) 
end)

Again, if a lot of players were playing this game, CHANGE "ds1" NAME BACK TO "GemsSaveSystem"!!! (line 2)

This discussion is preserved as it was. New answers, comments, and votes are closed.