How would I go about adding a tax system to money which the player earns?

I’m making a simple civilization-rp type game, similar to GRG or Thy Hood

I wanted to make a tax rate system, so any money that the player earns goes through a % tax, and they earn the inverse %. So if they were to make $2, and the tax rate is 50%, they are only given $1.
Problem is i am really confused on how i actually implement this, its incredibly confusing.

Im using a tax rate int value in replicated storage, and the player’s money is added to their leaderstats after performing an action which gives them money like chopping trees, harvesting crops, etc.

^ not really sure if some of that was necessary, but whatever

thanks for any replies!!

4 Likes

If your raw tax rate value is 0.5 (50%), then you can simply just do local taxedEarnings = actualEarnings - (actualEarnings*taxRate)

Well naturally you could multiply the earned amount by the percent remaining for the player.

Earned money * (percentage left after tax, so if tax is 30%, you would put 70% or 0.7)

Earned Money (2) * 0.5 (50%) = 1

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

ive got this code at the moment, trying to use what you suggested;
it does still work by adding the profit you’re meant to get, but it doesnt multiply the amount or anything

Odd. What’s the value of taxrate and profit?

the value of profit is 2, and the value of taxrate is 25

i mean thatd probably make the amount something like 50?? but i just wanted to see a result thatd sort of work

i mean, if i can get this to work at all im still not really sure how im going to get the money into the ruler’s bank or how to make it multiply correctly

I’m a little confused on what the problem is here now, so your moneytogive should be 2 - (2*25) which would be 2 - 50 or -48, but you mentioned that it’s not multiplying the value, so moneytogive is just 2?
My head hurts lol

well its supposed to be 75% of 2 so it should be giving 1.5, but it isnt multiplying at all or doing it correctly

maybe your using an integer vale. An Integer is any Whole Number on both the negative and positive sides of 0.
Just change the value to a Number Value which will let you have any type of number, including rational/irrational (math.round() is a very helpful tool), integer, whole.