Hi there! Im currently in the process of making a game and I need a script that allows me to click a button which changes the colour of a light that the button is assigned to. I am a bit confused as to what I need to do to make it work because i have tried altering my code multiple times and every time it hasnt worked. I would really appreciate some help because I have tried everything I can and I have not been able to get it to work.
Here is the code I have so far
local clickdetector = script.Parent:WaitForChild(“ClickDetector”) clickdetector.MouseClick:Connect(function(player) game.Workspace.pinkLight.Surfacelight.Color = BrickColor.new("Pink").Color end)
(pinkLight is the name of the light i want to change the color of)
Put the script and click detector in the part. Also lights use Color3, not brick color.
local clickdetector = script.Parent:WaitForChild(“ClickDetector”) clickdetector.MouseClick:Connect(function(player) script.Parent.SurfaceLight.Color = Color3.fromRGB(255, 170, 255) end)
Edit:
local clickdetector = script.Parent:WaitForChild(“ClickDetector”) local part = workspace:WaitForChild("pinkLight") --Waits for the part to load clickdetector.MouseClick:Connect(function(player) part.SurfaceLight.Color = Color3.fromRGB(255, 170, 255) end)
This would work so it changes every second:
while true do game.Workspace.pinkLight.Surfacelight.Color = BrickColor.Random().Color wait(1) end
BrickColor.Random().Color converts a random BrickColor to Color3 since lights use Color3 instead of BrickColor.
If you want to make it change every time you click, you'd do this:
local clickdetector = script.Parent:WaitForChild(“ClickDetector”) clickdetector.MouseClick:Connect(function(player) game.Workspace.pinkLight.Surfacelight.Color = BrickColor.Random().Color end)
If you want to make it pink when you click it, follow Utter_Incompetence's answer.
I hope this helps you.