Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

What is wrong with my Data Persistence script? [UNSOLVED]

I've got a script to assign 3 values to the player when he joins the game. It's not assigning the values though. Nothing in the output, it is purely just not working.

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: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 answer

You named it NotNew, but you're trying to access notnew.

1 comment

0

That fixed my problem, but the Values still don't spawn in.

This discussion is preserved as it was. New answers, comments, and votes are closed.