Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make the background color of a Gui change when clicked?

Asked by 11 years ago

How do I change the background color of a gui when a player clicked it?

2 answers

Log in to vote
0
Answered by 11 years ago

Depends on how you want it done.

This is the controlled version:

01ColorOne = 1, 0, 0
02ColorTwo = 0, 1, 0
03ColorThree = 0, 0, 1
04script.Parent.MouseButton1Down:connect(function()
05    if script.Parent.BackgroundColor == ColorOne then
06        script.Parent.BackgroundColor = Color3.new(ColorTwo)
07    elseif script.Parent.BackgroundColor == ColorTwo then
08        script.Parent.BackgroundColor = Color3.new(ColorThree)
09    else
10        script.Parent.BackgroundColor = Color3.new(ColorOne)
11end)

You could do a more complex one with math.random.

Ad
Log in to vote
0
Answered by
Dominical 215 Moderation Voter
11 years ago

You must put this in a TextButton

This code will change the color of the TextButton when clicked!

01-----
02color = "Black" -- put color you want here
03-----
04 
05 
06 
07sp=script.Parent
08 
09function click()
10sp.BackgroundColor3 = BrickColor.new(color).Color
11end

More info on TextButtons click here

Answer this question