@jenesuispasunevache That’s great. Next, move the actual leaderstats object to ServerScriptService as well. Right now, they’re on the player, meaning they are deleted when the player leaves the game, which can cause issues.
@RealJefff2000 The player doesn’t need to have direct access to their leaderstats objects, as the server handles all calculations regarding them. In fact, placing the leaderstats in ReplicatedStorage could open the door for hacking stats.
If the local player needs to have access to the values, a RemoteEvent will suffice – the actual leaderstat objects should strictly not be placed in ReplicatedStorage.
I did it and still printed nothing and now its the game that is underline in red in
if success then
paper.Value = paperData
rebirths.Value = rebirthsData
end
end
--- this one (under the this)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
DataStore:SetAsync("paper-"..player.UserId,player.leaderstats.Paper.Value)
DataStore:SetAsync("rebirths-"..player.UserId,player.leaderstats.Rebirths.Value)
end)
if success then
print("Success")
else
print("Failed")
end
end)
I meant the end not the end)
So the script should be:
if success then
paper.Value = paperData
rebirths.Value = rebirthsData
end
--Delete this one instead
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
DataStore:SetAsync("paper-"..player.UserId,player.leaderstats.Paper.Value)
DataStore:SetAsync("rebirths-"..player.UserId,player.leaderstats.Rebirths.Value)
end)
if success then
print("Success")
else
print("Failed")
end
end)
The game is probably shutting down before the PlayerRemoving function gets a chance to finish. Try hooking a function that yields a while to BindToClose.
Do this:
Join a server, open Dev Console [F9]
Then click server is logs, type in this:
game.Players.[Your name].leaderstats.Paper.Value = 1000
Then leave and rejoin. If it works, it works, if it doesn’t then you have to fix that line.
if success then
if paperData then ---delete that
paper.Value = paperData
rebirths.Value = rebirthsData
end
end --- and that
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
DataStore:SetAsync("paper-"..player.UserId,player.leaderstats.Paper.Value)
DataStore:SetAsync("rebirths-"..player.UserId,player.leaderstats.Rebirths.Value)
end)
end)
A big nice thank you to all the people who helped me out!!