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

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

Asked by
Oullim 0
7 years ago
-- 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

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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.

Ad

Answer this question