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 4 years ago
Edited 4 years ago
local DataStoreService = game:GetService("DataStoreService")
local T1 = DataStoreService:GetDataStore("SavePoints")

game.Players.PlayerAdded:Connect(function(Player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = Player
    local Point = Instance.new("IntValue")
    Point.Name = "Points"
    Point.Parent = leaderstats
end)

game.Players.PlayerRemoving:Connect(function(player)
    pcall(function()
        T1:SetAsync(player.UserId.."-Points",player.leaderstats["Points"].Value)
        print("Saved")
    end)
end)

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 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

I just got it worked :D

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

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

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

Answer this question