I have a datastore that is supposed to save the points of the player, for some reason, it doesn't work and because it is wrapped in a pcall, it does not send an error to fix.
Here the points script: (Works)
game.Players.PlayerAdded:connect(function(plr)
local ls = plr:WaitForChild("leaderstats")
local rank = Instance.new("IntValue",ls)
rank.Name = "Points"
rank.Value = 0
while true do
rank.Value = rank.Value + 5
wait(5)
end
end)
Here is the data script: (Does not work)
local dataStores = game:GetService("DataStoreService"):GetDataStore("ExtolDataStore")
local players = 0
game.Players.PlayerAdded:connect(function(plr)
players = players + 1
local points = plr:WaitForChild("leaderstats"):WaitForChild("Points").Value
local player_data
pcall(function()
player_data = dataStores:GetAsync("user_"..plr.UserId,points)
end)
if player_data ~= nil then
points = player_data else
points = 0
end
end)
local bindableEvent = Instance.new("BindableEvent")
game.Players.PlayerRemoving:connect(function(plr)
local points = plr:WaitForChild("leaderstats"):WaitForChild("Points").Value
pcall(function()
dataStores:SetAsync("user_"..plr.UserId,points)
print("Saved "..plr.Name.."'s Data")
players = players - 1
bindableEvent:Fire()
end)
game:BindToClose(function()
while players > 0 do
bindableEvent.Event:Wait()
end
end)
end)
Thank you to anyone who can help.

1 comment
Is the Value property not updating when your points variable is updated?