How to make buy max system

For example : I have 10,123,573 cash and buy max button is 11 cash per 1 time

I want to know how to get the amount of how much did can it buy until the cash is less than or equal to 11

hi,

can you please elaborate on your issue? it’s not entirely clear what you want to accomplish.

1 Like

Did you know buy max it’s like buy that thing until your cash can’t buy it anymore

1 Like

try something like this

-- variables
local cash = ??? -- replace with your cash value object
local price = 11

-- functions
local function buy()
    -- checking if player has enough money
    if cash.Value - price => price then
       -- subtract cash
       cash.Value -= price
    end
end

Something like this should do it

local player = game.Players.LocalPlayer

purchaseButton.MouseButton1Click:Connect(function()
	local money = player.leaderstats.money
	local itemCost = 11

	local maxQuantity = math.floor(money.Value/ itemCost) -- Calculate maximum quantity player can buy
	if maxQuantity > 0 then
		local totalCost = itemCost * maxQuantity
		money.Value -= totalCost -- do this on the server, else it's not gonna work
		
	end
end)

oh yes i should’ve use division

1 Like

just want to mention remember to use round(division-,5) so they don’t get a decimal amount and they don’t get more than they should

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.