-- 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?
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.