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.
COMMUNITY QUESTION
How do I get a button to change the colour of an image?
2 answers
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)
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.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
click detectors dont have a MouseButton1Click event