UPDATE
local stock = game.Players.LocalPlayer:WaitForChild("Stocks").ONE local cash = game.Players.LocalPlayer:WaitForChild("leaderstats").Cash local OPrice = game.Workspace.ONEVal.ONEPrice local a = game.StarterGui.CashNStuff.Frame.Investments.ImageLabel.TextLabel local a2= workspace.ONEVal.ONEstockownedamnt print(a2.Value) print(a.Text) print(OPrice.Value) print(cash.Value) print(stock.Value) script.Parent.MouseButton1Click:connect(function() if cash.Value >= OPrice.Value then stock.Value = stock.Value + 1 and cash.Value == cash.Value - OPrice.value and a2.Value == stock.Value a.Text = a2.Value else print("Not enough cash") end end)
You're attempting to do arithmetic +
on stock
, which is nil
, not a number.
nil + 1
doesn't make sense.
Why is stock
nil
?
You defined stock
as tonumber(a.Text)
. Let's look at the documentation for tonumber
:
Attempts to convert the arg into a number in base-10. If it cannot be converted, this function returns nil.
So if you pass tonumber
something that doesn't look like a number, you'll get back nil
. a.Text
must not be a simple decimal number like 15
. Either ensure it is (you can't if Buy1
is a TextBox) or handle the case where stock
is nil
separately.