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

DataStore doesn't seem to save my leaderboard?

Asked by 5 years ago
Edited 5 years ago
01local DataStoreService = game:GetService("DataStoreService")
02local T1 = DataStoreService:GetDataStore("SavePoints")
03 
04game.Players.PlayerAdded:Connect(function(Player)
05    local leaderstats = Instance.new("Folder")
06    leaderstats.Name = "leaderstats"
07    leaderstats.Parent = Player
08    local Point = Instance.new("IntValue")
09    Point.Name = "Points"
10    Point.Parent = leaderstats
11end)
12 
13game.Players.PlayerRemoving:Connect(function(player)
14    pcall(function()
15        T1:SetAsync(player.UserId.."-Points",player.leaderstats["Points"].Value)
16        print("Saved")
17    end)
18end)

Is anything wrongs with it? because each times i leave and join again it'll reset my points back to 0 ! and not even a single saves in it? btw i already enable Studio Access to API Services

0
Didn't work :( II_Minecraftsteves 15 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

I just got it worked :D

Ad
Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

The reason is because you never load the stats in after they join.

01game.Players.PlayerAdded:Connect(function(Player)
02local leaderstats = Instance.new("Folder");
03leaderstats.Name = "leaderstats";
04leaderstats.Parent = Player;
05local info = T1:GetAsync(Player.UserId.."-Points);
06local Points = Instance.new("IntValue");
07Points.Name = "Points";
08Points.Parent = leaderstats;
09if(info) then
10Points.Value = tonumber(info);
11else
12T1:SetAsync(Player.UserId.."-Points", 0);
13Points.Value = 0;
14end
15end)
0
Didn't work II_Minecraftsteves 15 — 5y
0
It is a ServerScript right? Make sure it is not a LocalScript, and place it in ServerScriptService. GeneratedScript 740 — 5y
0
yes it's a Serverscript Script and i'm already put it in the ServerscriptService II_Minecraftsteves 15 — 5y
0
try changing IntValue to NumberValue. GeneratedScript 740 — 5y
View all comments (2 more)
0
Nvm i just got it worked :D II_Minecraftsteves 15 — 5y
0
What was wrong with it? GeneratedScript 740 — 5y

Answer this question