Need assistance with setting light color to part color

The script I am writing needs to set the color of a spot light to match the color of the button that is pressed. Here is what I have, I’ve tried looking into the Color3 values and etc but I am not sure how get the color3 values from the part through the script to change the light color. This script is suppose to be a copy and pasted into multiple parts which is why its basic (inefficient, I know, but it’s to get what I need done for now so I know it works until I can make it control multiple buttons)

color = script.Parent.Color
function onClicked()
	workspace.SpotLightControls.SpotLights.SpotLightLeft.Color = color
	workspace.SpotLightControls.SpotLights.SpotLightRight.Color = color
	workspace.SpotLightControls.SpotLights.SpotLightCenter.Color = color	
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)

You need to capitalize the “c” in :connect.

color = script.Parent.Color
function onClicked()
	workspace.SpotLightControls.SpotLights.SpotLightLeft.Color = color
	workspace.SpotLightControls.SpotLights.SpotLightRight.Color = color
	workspace.SpotLightControls.SpotLights.SpotLightCenter.Color = color	
end
script.Parent.ClickDetector.MouseClick:Connect(onClicked)

is that really necessary? the script works else where, where i’m not trying to call a color3 value. Tried it anyway and it still doesn’t work

:connect works when lowercase, that isn’t the issue here. What classes are the SpotLightLeft (and the rest of them) and script.Parent?

I’m also not fully understanding your question here. Is this code not working? Or are you looking for a way to implement this on a broader scale to make it apply to different buttons and lights.

I am completely sorry, I just saw my error :tired_face: I was referencing the part of the spotlights rather than the spotlight itself, so it should of been
workspace.SpotLightControls.SpotLights.SpotLightLeft.SpotLight.Color = color instead of workspace.SpotLightControls.SpotLights.SpotLightLeft.Color = color
Thank you for pointing out classes otherwise I wouldn’t of looked and been so confused… It works now, so thank you for responding atleast!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.