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

How do I make this work? there is not an error now just doesn't work... I'm so confused.

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)

1 comment

0

it doesn't get errors it just doesn't work...

1 answer

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.

10 comments

1

Actually he defines stock twice

0

Kiriot how should I make it define it once

0

well i mean how should i fix this

0

the ONE.Value is 0 so im confused

0

why are you changing a.text to a.text lol

0

on line 6 and 7 your literally changing a text that is already string to string lol

0

idek

0

Just use a number Value Instead of a string value

0

i thought thats what i was using

0

if I use a number value it says error about a boolean value

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