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

Data persistence not working?

Asked by 8 years ago

I have already created a little GUI bar that should show the player how much money he/she has. However, this isn't working.

moneyKey = 100
game.Players.PlayerAdded:connect(function(player)
    if player:WaitForDataReady() then
        local MoneyBox = game.StarterGui.ScreenGui.MoneyBox
        local ls = Instance.new("IntValue", player)
        ls.Name = "leaderstats"
        ls.Parent = player

        local money = Instance.new("IntValue", ls)
        money.Name = "Score"
        money.Parent = ls
        money.Value = player:LoadNumber(moneyKey)
        MoneyBox.Text = money.Value
    end
end)

game.Players.PlayerRemoving:connect(function(player)
    if player:FindFirstChild("leaderstats") then
        player:SaveNumber(moneyKey, player.leaderstats.money.Value)
    end
end)

On line 13 I try to make MoneyBox.Text equal to money.Value (i.e, how much money the player has). However, it doesn't actually do this. What have I done wrong here?

0
datapersistence is deprecated. Use DataStore instead davness 376 — 8y
0
Not everyone had learned DataStores. They are quite simple to be honest, but if he hasn't learned it, then DataPersistence is a fine substitute. dyler3 1510 — 8y

Answer this question