Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited 5 years ago

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) `

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

2 answers

Log in to vote
0
Answered by 5 years ago

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

0
Weird.. Doesn't work for me, any ideas? GooCandy 2 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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)

Answer this question