How would I apply the boosts to the player?

So I am learning to program while also trying to make a category of games I enjoy(Button Simulators) and after realizing how much my code was repeating and how many nested loops I had. I ended up with an OOP setup for a button. I do not know how I would exactly go about giving the player the boosts.

Lets say there is currently only Cash, Multiplier and Rebirth like it is here with their associated boosts:

local ButtonTypeData = {
    Multiplier = {
        Resets = false,
        Boosts = {
            Cash = 1.0
        }
    },

    Rebirth = {
        Resets = true,
        Boosts = {
            Multiplier = 1.0
        }
    },

    SuperRebirth = {
        Resets = true,
        Boosts = {
            Rebirth = 1.0,
            Multiplier = 1.5,
            Cash = 1.25,
        }
    },
}

return ButtonTypeData

How would I exactly provide these to the player? Below is a function from my module of how the button works, when the player can afford the button they will obviously get the amount that the button states it will give, and lose whatever the price was. But would I instead make a separate script that is like a BoostsHandler? and like it would check how much of each “tier” the player has and applies a certain formula or is there an easier or better way of going about this.

function Button:Purchase(player)
    if not self:CanAfford(player) then
        print(player.Name .. " is broke as FUCK!")
        return
    end

    local leaderstats = player:FindFirstChild("leaderstats")
    local currency = leaderstats:FindFirstChild(self.PriceType)
    local stat = leaderstats:FindFirstChild(self.StatName)

    if currency and stat then
        currency.Value -= self.Price
        stat.Value += self.Bonus
        print(player.Name .. "bought" .. self.StatName .. "for" .. self.Price)
    end
end

Sorry if like this is a stupid question I am just trying to improve and trying to avoid tutorial hell and AI for now

You could just have an assigned boost value/variable, which you would add the boosts to when initializing it.

Then in your function to award money, multiple the money with the boosts, and award that value instead of the raw money value.

But like lets say eventually I have like 100 separate tiers that apply multipliers to a lot of different categories thats why i just dont know how to not make it look messy

Loop through your data table, then
if v.Boosts.Multiplier then
myVal = myVal * v.Boosts.Multiplier
end

Something along the lines of that.

Alright thank you ill try that

1 Like

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