im making a basic civilization game, like generic roleplay gaem
ive already made the sysytem for the tax rate being in place, and the rate also changing, but how would i actually implement the tax being added onto the profit of something that a player gains?
assuming they were to make $2, but the tax rate is 25%, they only make 75% of the profit, but im really not sure how to add it.
my code is currently looking like this:
local Players = game:GetService("Players")
local function onAxeTouch(otherPart)
local log = otherPart.Parent:FindFirstChild("treedetect")
local treeHealth = log and log:FindFirstChild("TreeHealth")
local profit = log:FindFirstChild("Profit")
local taxrate = game.ReplicatedStorage.TaxRateValue.Value
local moneytogive = profit - (profit*taxrate)
if treeHealth then
treeHealth.Value = treeHealth.Value - 1
if treeHealth.Value <= 0 then
local player = Players:GetPlayerFromCharacter(otherPart.Parent)
if player then
local leaderstats = player:FindFirstChild("leaderstats")
local cash = leaderstats and leaderstats:FindFirstChild("Cash")
if cash then
cash.Value = cash.Value + moneytogive
end
end
end
end
end
local function setupAxe(axe)
local handle = axe:FindFirstChild("Handle")
if handle then
handle.Touched:Connect(onAxeTouch)
end
end
however this doesn’t work and just adds the flat value
shouldn’t you be using profit.Value here?
Anyways, assuming that isn’t the issue, you said that the cash adds the amount before getting taxed, correct?
uhhh, well i think it just adds the original amount without the tax, yeah.
which isnt the intention
also just to note i did have a post before but it went inactive so i made this 1
yo sorry i was busy, but ill try this soon, or tommorow if i cant get to it. pretty late for me
but i seriously appreciate all the help its very nice!!
oh i know how the whole tax thing works and how im intending for it, but i was referring to the mathematical process in the code, and making it work
mainly because im not too good at coding as is, not to mention the math part of it
You’re not extracting the value from Profit, you’re instead multiplying the Instance with a number. @domboss37 mentioned that you probably meant to index the Value of Profit instead of directly doing math with the Instance.
local function tax(money: number, rate: number): number
return money*(1-rate) -- x-x*y == x*(1-y)
end
local money = 2 --2$
local rate = 0.25 --25%
local afterTax = tax(money, rate)
print(afterTax) --1.5$