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

(solved) How do I make a colour changing surface/spotlight?

Asked by 4 years ago
Edited 4 years ago

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)

2 answers

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

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)
0
Hi! Thanks a lot for you help. So would i put this in the button and then link that to a remote event? Also would this work if i wanted to control the light when the button is a different block? ANNASTASlA 10 — 4y
0
Oh you can put this in a normal script. If you wanted to control the light remotely, I'll edit my answer. Utter_Incompetence 856 — 4y
0
Yeah thats what i want it to do so that would be very helpful :) ANNASTASlA 10 — 4y
0
Done! If you have any further questions, do ask. Utter_Incompetence 856 — 4y
View all comments (6 more)
0
Thank you so much for your help! ANNASTASlA 10 — 4y
0
No problem :) Utter_Incompetence 856 — 4y
0
Alright, i still cant get it to work. Do each parts of the script go in different scripts? Like for example the first part would go in the buttons script and the second part would go in the lights script? ANNASTASlA 10 — 4y
0
No, keep all code in one script. Utter_Incompetence 856 — 4y
0
Hi again. I still cant get it to work. Would it be possible to contact on discord so i can show you what im doing in more detail so you can show me where im going wrong? ANNASTASlA 10 — 4y
0
Sure. Incompetence#8077 Utter_Incompetence 856 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

Answer this question