I need help on scripting a Spotlight object so when its parent object's BrickColor is bright green, the light will be enabled and when the BrickColor is bright red, the light will be disabled.
I've tried scripting this myself but failed because I'm new to scripting with lua.
Here is what I tried so far:
while true do
if Game.Workspace.CartRegen.Cart.On.BrickColor = "Bright red" then
Game.Workspace.CartRegen.Cart.On.SpotLight.Enabled = false
else if Game.Workspace.CartRegen.Cart.On.BrickColor = "Bright green" then
Game.Workspace.CartRegen.Cart.On.SpotLight.Enabled = true
end
end
Please help me fix this script.

6 comments
I tried putting this script into the spotlight but is still doesn't work in-game.
Is there any output?
Not that I know of.
Try this edit.
Still no result. am I maybe putting this in wrong? like do I have to change something in your edit?
Are you sure your pathway to the variable Object is correct?