# How does this work?

Hello, I made a script to calculate roblox tax but the prices are not calculated correctly.

function RobloxTax(price)
NewPrice = price * 0.7
DividedPrice = price / 0.7
SubtractedPrice = NewPrice - DividedPrice
print("Amount for Original Price: "…SubtractedPrice)
end

RobloxTax(1500)

do u not want it to have the decimals or what?

The price is being saved so when I do RobloxTax(1500) it is being all put together

maybe because u change the price a few times?
edit: nvm that cant be why im just dumb lol

The price is being calculated when I call the function and it prints out numbers, I want to figure out why the calculations are being put together

thats because u did the prints in the function without a wait thats why

1 Like

Could you explain what you are trying to achieve with the function? For example, I don’t really see the purpose of DividedPrice or SubtractedPrice in calculating the taxed amount.

DividedPrice - SubtractedPrice = Price for original price so if I had 1500, 70 percent of it would = 1050, if i subtract them it should be 450, which is the required price I need to add with so I can get the price of 1500 correctly with tax, so 450 is the fee. I cant really explain it well but if you look at the code it shouldnt be hard to understand

That didn’t work, here is my updated code

function wait(seconds)
local start = os.time()
repeat until os.time() > start + seconds
end

function RobloxTax(price)
NewPrice = price * 0.7
DividedPrice = price / 0.7
SubtractedPrice = NewPrice - DividedPrice
wait(1)
wait(1)
print("Amount for Original Price: "…SubtractedPrice)
end

RobloxTax(1500)

(I did this in mobile, thats why I added the wait function)

I think the main issue I’m having with understanding your logic is with the fact that tax isn’t usually calculated like that. If you take VAT for example it would be something like:

``````local price = 1000

price += price*0.35 -- where 0.35 would be a 35% tax bracket
end

-- if the price included the tax and you know the tax bracket
function taxedPrice()
return price/1.35
end
``````

I really don’t understand the logic you’re using for calculating tax.

I wanted it to be in one function but i guess that works

You can make it into a single function. I’m just giving an example of the math you could use. Having said that I’m not sure why you would want them in a single function.

The first function returns the price with the tax added (if the price didn’t have the tax incorporated previously). By comparison, the second function returns the price if it already has the tax incorporated. If you wanted the amount of tax itself you could just do:

``````function addedTax(price)
return price*1.35
end

local tax = addedTax(price) - price

-- or if you have the price with the tax incorporated

function taxedPrice(price)
return price/1.35
end

local tax = price - taxedPrice(price)
``````