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

attempt to perform arithmetic on a nil value???????

what is wrong with this it works but i keep getting this error: 5: attempt to perform arithmetic on a nil value

local pointlabel = script.Parent.Points
local pointvalue = game.Players.LocalPlayer:WaitForChild("Stats"):WaitForChild("Points")

pointvalue.Changed:connect(function()
	pointlabel.Text = pointvalue.Value - tonumber(pointlabel.Text).."+" 
	wait(2)
		pointlabel.Text = pointvalue.Value
end)



1 answer

✓ Accepted answer

Haven't tested it myself but I'd imagine it's the call for tonumber(pointlabel.Text) being a nil value Of which you can't perform arithmetic on a nil value. I guess simply change pointLabel.Text to a default value upon starting the game or adding the player to the game. Or upon creating the GUI

2 comments

0

You might also want to add a debounce so that it cannot try to read pointlable.Text while it has the addition symbol within it.

0

Subsequently you might want to add a queue system in so you still get all the beautiful how many points I just received thingy, but it still doesn't try to tonumber() on a string that cannot be processed as such.

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