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

By using script to create GUI and click it to change color and <click it again to undo color>?

Asked by 8 years ago
local Gui = Instance.new("ScreenGui")
Gui.Name = "SpectateGui"
local Button = Instance.new("TextButton")
Button.BackgroundColor3 = Color3.fromRGB(1, 137, 255)
Button.BackgroundTransparency = 0
Button.Position = UDim2.new(0, 15, 1, -90)
Button.Size = UDim2.new(0, 190, 0, 20)
Button.Text = ({[false] = "Spectating", [true] = "Playing"})[Playing[Player]] .. ""
Button.Parent = Gui
Button.MouseButton1Click:connect(function()
Playing[Player] = not Playing[Player]
Button.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
Button.Text = ({[false] = "Spectating", [true] = "Playing"})[Playing[Player]] .. ""
end)

I have successfully made GUI with clickable button.

When I click it and it changes to "Spectating" and red color and when I want to start playing and I have to click button again to change it back to "Playing" but red color won't change back to blue color?

1 answer

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

The problem is that you never actually set it back to blue. To be consistent with the rest of the code, replace lines 4 and 12 with this:

Button.BackgroundColor3 = ({[false] = Color3.fromRGB(255, 0, 0), [true] = Color3.fromRGB(1, 137, 255)})[Playing[Player]]

Your way of setting the text is clever but not very neat. I'd either use if statements, or if you'd rather keep it on one line, you can do this:

Button.Text = Playing[Player] and "Playing" or "Spectating"
0
Ahh, thanks you! Stanleyloganlego 10 — 8y
Ad

Answer this question