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

Why won't this save my leaderboard stats? After I rejoin

Asked by 5 years ago
Edited 5 years ago

datstore = game:GetService("DataStoreService") local datast1 = datstore:GetDataStore("Yuan") local datast2 = datstore:GetDataStore("Gems") 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 = datast1:GetAsync(plr.UserId) or 0 datast1:SetAsync(plr.UserId, gems.Value) cash.Value = datast2:GetAsync(plr.UserId) or 0 datast2:SetAsync(plr.UserId, cash.Value) gems.Changed:Connect(function() datast1:SetAsync(plr.UserId, gems.Value) end) cash.Changed:Connect(function() datast2:SetAsync(plr.UserId, cash.Value) end) end)
0
This code should work, are you getting any errors/warnings ingame? Check /console User#22604 1 — 5y
0
No im not getting any errors it just won't save User#22788 5 — 5y
1
it should be in a regular script greatneil80 2647 — 5y
0
Its in a serverscript and it is inside ServerScriptService User#22788 5 — 5y
View all comments (5 more)
0
are you changing gems' value locally or server side User#22604 1 — 5y
0
locally User#22788 5 — 5y
0
the server cannot tell when a value is changed locally, you'd have to use remote events to tell the server when to update the value User#22604 1 — 5y
0
Who downvoted this..? greatneil80 2647 — 5y
0
Note that, unless 'gems' and 'cash' rarely change, you're likely to get throttling problems by calling SetAsync every time they change (at least you might when you have more players in a server than just yourself). chess123mate 5873 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

You have to activate the API services thingy in your game settings.

Ad

Answer this question