✓ Accepted answer
You can use a generic for loop to loop through all the children in the alarm, check if the child in question is a SpotLight and change it's color if it is a SpotLight.
I would suggest making this in a function so you can call it for different alarms. If we use a function for this, we can also use the built-in assert function. Assert has two arguments: A boolean and a string. Assert checks if the boolean is false and throws an error into the output with the message of the string given.
This is useful as we can add a statement in place of a boolean in the assert function so that our function stops if a certain condition is not met and allows us to give custom error messages.
Code:
function changeAlarmLight(parent,r,g,b)
assert(parent:IsA("Model"), "ERROR: Parent is not a model!")
assert(tonumber(r), "ERROR: Red value is nil or not a number!")
assert(tonumber(g), "ERROR: Green value is nil not a number!")
assert(tonumber(b), "ERROR: Blue value is nil or not a number!")
if r > 1 then r = r/255 end
if g > 1 then g = g/255 end
if b > 1 then b = b/255 end
for _,light in pairs(parent:GetChildren()) do
if light:IsA("SpotLight") then
light.Color = Color3.new(r,g,b)
end
end
end
Usage example:
changeAlarmLight(game.Workspace.Alarm,255,0,0)
changeAlarmLight(game.Workspace.Part,255,100,20)
changeAlarmLight(game.Workspace.Alarm1,true,0,0)
I hope my answer helped you. If it did, be sure to accept it.
Read more on the asset function here.
1 comment
Well that attempt at formatting failed.