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

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

Asked by 5 years ago
Edited 5 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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)

0
it doesn't get errors it just doesn't work... JohnerDev 27 — 5y

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
5 years ago

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.

1
Actually he defines stock twice Amiaa16 3227 — 5y
0
Kiriot how should I make it define it once JohnerDev 27 — 5y
0
well i mean how should i fix this JohnerDev 27 — 5y
0
the ONE.Value is 0 so im confused JohnerDev 27 — 5y
View all comments (6 more)
0
why are you changing a.text to a.text lol seith14 206 — 5y
0
on line 6 and 7 your literally changing a text that is already string to string lol seith14 206 — 5y
0
idek JohnerDev 27 — 5y
0
Just use a number Value Instead of a string value seith14 206 — 5y
0
i thought thats what i was using JohnerDev 27 — 5y
0
if I use a number value it says error about a boolean value JohnerDev 27 — 5y
Ad

Answer this question