I am trying to make a script that saves client stats for when it leaves the game then loads the client stats when it joins the game but it doesn't save the client's stats. I scripted this in a server script and I think is because is not compatible to Filtering Enabled, any ideas?

function onPlayerEntered(player)
wait(3)
player:WaitForDataReady()
repeat wait() until player:FindFirstChild("Data")
if player.DataReady then
if player:findFirstChild("Data") then
local score = player.Data:GetChildren()
for i = 1,#score do
local ScoreLoaded = player:LoadNumber(score[i].Name)
wait()
if ScoreLoaded ~= 0 then
score[i].Value = ScoreLoaded
end
end
end
end
end

function onPlayerLeaving(player)
if player:findFirstChild("Data") then
local score = player.Data:GetChildren()
for i = 1,#score do
player:SaveNumber(score[i].Name,score[i].Value)
end
end
end
game.Players.PlayerAdded:connect(onPlayerEntered)
game.Players.PlayerRemoving:connect(onPlayerLeaving)

1 comment

1

This method of saving is deprecated and a better service that offers much more functionality is available. Instead of LoadNumber, see DataStoreService and various tutorials of it to get started: https://developer.roblox.com/articles/Data-store