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

Why doesn't this data persistence script work?

Asked by 9 years ago

I have a script that saves a player's leaderstats for how many kills that player has achieved. Here's the script:

game.Players.PlayerRemoving:connect(function(player)
    local s = player:findFirstChild("leaderstats")
    if s then
        local k = s:findFirstChild("Kills")
        player:SaveNumber("kill", k.Value)
    end
end)

game.Players.PlayerAdded:connect(function(player)
    if player:WaitForDataReady() then
        player:LoadNumber("kill")
    end
end)

The problem is that the script doesn't do anything. I tried putting print("check") in both lines of code and nothing showed up in the output. Any help?

1 answer

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

LoadNumber returns a number.

You aren't doing anything with that number. Line 11 is just like setting

math.sqrt(15)

on its own.

Set the value of kills:

player:WaitForChild("leaderstats"):WaitForChild("Kills").Value =
    player:LoadNumber("kill")
Ad

Answer this question