Button GUI Colour switch

Hello! I know this is simple but unsure how to do it.

how do you script it so you can toggle between the colour of the selected button the player clicks

I have 2 buttons which toggle the FOV for the player.
image

local Fov = script.Parent

Fov.fov70.MouseButton1Click:Connect(function()

workspace.Camera.FieldOfView = 70

end)

Fov.fov50.MouseButton1Click:Connect(function()

workspace.Camera.FieldOfView = 50

end)

but I would like it so when the player clicks 1 button it turn to this colour (39, 181, 255) and the 1 that’s not selected turns to this grey (130, 130, 130)

Thank you!

Inside the function you can reference the active and inactive buttons since you know which one is being pressed, and color them accordingly. For example, the fov70 button event’s code could include:

Fov.fov70.BackgroundColor3 = Color3.fromRGB(39, 181, 255)--set fov70 buttons' color to indicate its active
Fov.fov50.BackgroundColor3 = Color3.fromRGB(130, 130, 130)--set the other button's color to indicate its inactive

And vice versa, for the fov50 button.

2 Likes

ahhhhhhhh yes that would make sense!

not sure why I didn’t think of it that way LOL

thanks again :slight_smile:

1 Like