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

Will this Data Persistence work?

Asked by 10 years ago

I made a script but I don't know if it will work. Can you take a look please? Can you tell me if this will fully work and if there is any mistakes? :)

This script is to save the score.

function onPlayerEntered(player)
wait()
player:WaitForDataReady()
repeat wait() until player:FindFirstChild("leaderstats")
if player.DataReady then
if player:findFirstChild("leaderstats") then
local score = player.leaderstats: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("leaderstats") then
local score = player.leaderstats: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)

This one is just the leaderboard.

function onPlayerEntered(newPlayer)

    local stats = Instance.new("IntValue")
    stats.Name = "leaderstats"

    local mins = Instance.new("IntValue")
    mins.Name = "Recs"
    mins.Value = 0


    mins.Parent = stats

    stats.Parent = newPlayer
    end

game.Players.ChildAdded:connect(onPlayerEntered)

Answer this question