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

What is wrong with this stats/DataStore script?

Asked by 10 years ago

I've got a script to assign 3 hidden values to the player as they join, but it doesn't work. I get nothing in the output either, it just doesn't assign the values.

wait(2) -- wait for the character to load

pointsKey = "PlayerPoints"
coinsKey = "PlayerCoins"
newKey = "PlayerNew"

function assignValues(plr)
    plr:WaitForDataReady();
    points = Instance.new("NumberValue")
    coins = Instance.new("NumberValue")
    notnew = Instance.new("BoolValue")


    --new
    notnew.Parent = plr
    notnew.Name = "NotNew"
    notnew.Value = plr:LoadBoolean(newKey)

    --points and coins
    points.Parent = plr
    points.Name = "Points"

    coins.Parent = plr
    coins.Name = "Coins"

    if notnew.Value == false then --check if player is new
        plr.NotNew.Value = true
        plr.Points.Value = 0
        plr.Coins.Value = 0
            if plr.PlayerGui.ScreenGui.Tutorial.Visible == false then
                plr.PlayerGui.ScreenGui.Tutorial.Visible = true
                plr.PlayerGui.ScreenGui.Tutorial.Position = UDim2.new(0, -600, 0, 100)
                plr.PlayerGui.ScreenGui.Tutorial:TweenPosition(UDim2.new(0,500,0,100), "Out", "Bounce", 1)
            end
    elseif notnew.Value == true then
        plr.Points.Value = plr:LoadNumber(pointsKey)
        plr.Coins.Value = plr:LoadNumber(coinsKey)
    end

    points.Changed:connect(function() saveStats(plr) end)
    coins.Changed:connect(function() saveStats(plr) end)
    notnew.Changed:connect(function() saveStats(plr) end)

end

function saveStats(plr)
    --coins and points save
    plr:SaveNumber(coinsKey, plr.Coins.Value)
    plr:SaveNumber(pointsKey, plr.Points.Value)
    --new save
    plr:SaveBoolean(newKey, plr.NotNew.Value)
end

game.Players.PlayerAdded:connect(assignValues)




1
Just so you know, this script attempts to utilize Data Persistence, not DataStores. They are two separate things. adark 5487 — 10y
1
You should not be using `wait(2)` at the top since you are attempting to hook into `PlayerAdded`. BlueTaslem 18071 — 10y
0
BlueTaslem is right, never use wait() when PlayerAdded is involved. ZeroBits 142 — 9y

Answer this question