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

Script has a fault when a large number is entered, what can I do to fix?

-- Mouse Clicked function
script.Parent.MouseButton1Click:connect(function()
if	 script.Parent.Parent.Parent.Parent.Frame.Money.MoneyVal.Value >= (script.Parent.Parent.Amount.Value.Value * script.Parent.Parent.Stock.StockVal.Value) then		
		script.Parent.Parent.Stock.StockVal.Value = script.Parent.Parent.Stock.StockVal.Value + script.Parent.Parent.Amount.Text

else
		warn("You have either tried to buy negative or higher than you can afford of shares")
end
end)

so this little code segment here is supposed to give me a stock if I put in an amount that I can afford, though when I put in a large number it still gives me the stock, why is this?

1 answer

I think you might have confused <= and >=. Right now, you're checking to see if they're spending more than they have, and in that case you give it to them.

So try replacing

if   script.Parent.Parent.Parent.Parent.Frame.Money.MoneyVal.Value >= (script.Parent.Parent.Amount.Value.Value * script.Parent.Parent.Stock.StockVal.Value) then

with

if   script.Parent.Parent.Parent.Parent.Frame.Money.MoneyVal.Value <= (script.Parent.Parent.Amount.Value.Value * script.Parent.Parent.Stock.StockVal.Value) then

That will ensure that they can only spend as much as they actually have.

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