#Best way to handle button upgrade and purchases

1 messages · Page 1 of 1 (latest)

main raven
#

Okay so im making a incremental type of game as shown in the image, and i want to know how i can do these things below effectiely and right. I use profile store and would just like to know how i should handle these without starting on the wrong foot.

  • First, how would i handle purchasing?
  • Second, how would you know how much to increase the cost and value increase/decreased each time?
  • Thirdly, how do you handle the constant button color changing. Do you use a script in each button because that seem excessive
#

Now i would like to say that i did have a go at trying to figure this out myself and i had the idea to use a module script within my server script which has all the profile store stuff inside. The script is seen as below but im not sure if its a good idea to handle it like this or if it will even work.

local Workspace = game:GetService("Workspace")

local UpgradeBoard = Workspace.UpgradeBoard

local FasterSticksButton = UpgradeBoard.SurfaceGui.MaxCapacityFrame.BuyButton

local module = {}

FasterSticksButton.Activated:Connect(function(player : Player)
    local value = player:GetAttribute("SpawnSpeed")
    
    if value > 0.2 then
        player:SetAttribute("SpawnSpeed", value - 0.2)
    else
        warn("Player has the max upgrade")
    end
end)

return module
#

any kind of help would be much appreciated

signal elm
#

I would recommend using a more structuralised programming style like OOP.

Currently im making an incremental myself and im just about to work on this. What i have in mind is this;

A modulescript that holds all the info about each upgrade like this:

local upgrades = {
  ["CashMulti"] = {
    maxLevel = 100,
    GetNextUpgradeCost = function(level)
      return level ^ 2
    end,
    description = "Multiplies cash earned by x1+(level * 2)"
    }
}

return upgrades

And then i would have a script that uses these attributes to make it actually function without having to manually type each connection so i just have to add a table in the modulescript if i want to add an upgrade.

main raven
#

Make another script that would handler it via a remote function, with another function calculating the cost

#

Also thanks for replying