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

How do I get a button to change the colour of an image?

Asked by 6 years ago

I need to make a script that could change the ImageColour3 of an image via a button. I have tried a few other scripts but these appear to be for the wrong thing.

https://gyazo.com/1120e5694a18f4f6a97acd7f150e0523

https://gyazo.com/642a306960fa9b70552cf34e46b49d64

2 answers

Log in to vote
1
Answered by
AmWrath 41
6 years ago

On your button you would want to use a MouseButton1Click event and connect it to a function that references your image and changes it based on the click. For example:

local button = script.Parent
local image = script.Parent:FindFirstChild('image')

button.MouseButton1Click:Connect(function()
    image.ImageColor3 = Color3.fromRGB(255,255,255) -- changing the color of the image to white
end)
0
click detectors dont have a MouseButton1Click event theking48989987 2147 — 6y
Ad
Log in to vote
1
Answered by
Rheines 661 Moderation Voter
6 years ago

If you're trying to change the color of Unlit via the ClickDetector you need to connect a function to a MouseClick event on that detector.

local image= script.Parent.Parent.Light.SurfaceGui.Unlit
local detector = script.Parent.ClickDetector

--Connecting MouseClick to the ClickDetector
detector.MouseClick:Connect(function()
    image.ImageColor3 = Color3.fromRGB(0,0,0) -- change it your new RGB color.
end)

Make sure to put it in the same place as the script you currently have.

Answer this question