Tycoon buttons help

Hey everyone! So I don’t have a script but I do have a question. I am making a tycoon right now and I want when a button is touched, another button fades in so they can buy more things. I have thought about, how to do it but I could never come to a solution. Does anyone know what I could do to make this happen?

A quick example:

local button1 = part
local button2 = part
local button2On = false 
local button1On = true

     if button1On == true then -- Checks if it's on
            do stuff 
             button1On = false  -- turns it off
               button2On = true -- turns 2nd button on

if button2On == true then -- checks if it's on
do stuff 
button2On = false  -- turns 2nd button off

Also, if you want things to fade in use tweens. Tween is short for inbetween, it’s basically interpolation. An example:

local result = {}
result.Transparency = 0 -- Makes our goal transparency 0

local info = TweenInfo.New(time) -- Creates tween info, much more options but they are optional

local tween = game:GetService("TweenService"):Create(button, info, result) -- Creates a tween for button with info as the TweenInfo and result as the goal
1 Like

I was thinking about using TweenService, but is there a way to make a tween and use it for all of the buttons? Because I don’t want to have to make 40 tweens.

Well, you could make one goal table and one info table. But you have to do Service:Create for each one. For example you could do:

local goal = {}
etc etc 
local info = TweenInfo.New(etc etc)

-- Then make multiple for different buttons
local tween1 = Service:Create(button1, info, goal) 
local tween2 = Service:Create(button2, info, goal)
1 Like

Assuming you’re using a different script for every single button, I would use a module to Tween. If you created a TweenHandler module, you could create one method to tween everything.


local TweenHandler = {}

--// Services
local TweenService = game:GetService("TweenService")

--// Functions
function TweenHandler:TweenPart(part) --// Tween given instance
      local Tween = TweenService:Create(part, TweenInfo.new(--[[Whatever tweeninfo you want for all of them]]--, {--[[Whatever tween value you are using--]]

return TweenHandler

This module would fire the same exact tween for all of your buttons. As long as it’s required.


--// Modules
local TweenHandler = require(game.ReplicatedStorage.TweenHandler)

--// Constants
local CURRENT_PART  = game.Workspace.p1
local NEXT_PART = game.Workspace.p2

--// Event handler
      if game.Players:GetPlayerFromCharacter(hit.Parent) then

This is a super rough example, but it should get the point across of how to make the fade you want.

ohhhhh, that makes a lot of sense, I didn’t even know that tweenhandler was a thing, thanks :))

For some odd reason, it doesn’t fade out.

This is the script I made

local TweenHandler = {}

local TweenService = game:GetService("TweenService")

function TweenHandler:TweenPart(part)
	local info = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
	local Tween = TweenService:Create(part, info, {Transparency = 1})

return TweenHandler

Then this one

local TweenHandler = require(game.ReplicatedStorage.TweenHandler)

local part = game.Workspace.button

	if game.Players:GetPlayerFromCharacter(hit.Parent) then

I know I didn’t add the other part i just wanted to test out the fade.

Where is the TweenHandler and what type of script is it?

I put the tween info and all of that in the module in rep then I made a script inside of the part.