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

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

Asked by 7 years ago

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

Log in to vote
0
Answered by
Pejorem 164
7 years ago

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

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. Pejorem 164 — 7y
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. Pejorem 164 — 7y
Ad

Answer this question