I am making a traffic light that changes upon a variable, and I keep getting the error message: Label is not a valid member of Model “Workspace.Crossing1.ControlBox”. This is my code,
local TrafficLight = script.Parent
local RedLight = game.Workspace.TrafficLight.RedLight
local YellowLight = game.Workspace.TrafficLight.YellowLight
local GreenLight = game.Workspace.TrafficLight.GreenLight
local RedPointLight = game.Workspace.TrafficLight.GreenLight.PointLight
local YellowPointLight = game.Workspace.TrafficLight.YellowLight.PointLight
local GreenPointLight = game.Workspace.TrafficLight.GreenLight.PointLight
while true do
if script.Parent.Parent.Crossing1.ControlBox.IsOn.Value == true then
wait(5)
RedLight.Transparency = 0.8
GreenLight.Transparency = 0
YellowLight.Transparency = 0.8
elseif script.Parent.Parent.Crossing1.ControlBox.IsOn.Value == false then
RedLight.Transparency = 0
GreenLight.Transparency = 0.8
YellowLight.Transparency = 0.8
end
end
Why are you specifying game.Workspace? The code should read as follows:
local TrafficLight = script.Parent
local RedLight = TrafficLight.RedLight
local YellowLight = TrafficLight.YellowLight
local GreenLight = TrafficLight.GreenLight
local RedPointLight = RedLight.PointLight
local YellowPointLight = YellowLight.PointLight
local GreenPointLight = GreenLight.PointLight
while true do
if script.Parent.Parent.Crossing1.ControlBox.IsOn.Value == true then
wait(5)
RedLight.Transparency = 0.8
GreenLight.Transparency = 0
YellowLight.Transparency = 0.8
elseif script.Parent.Parent.Crossing1.ControlBox.IsOn.Value == false then
RedLight.Transparency = 0
GreenLight.Transparency = 0.8
YellowLight.Transparency = 0.8
end
end
We do it this way so if the model/part/whatever gets moved, we don’t have to change the references. Also, you have an issue where RedPointLight was referencing GreenLight. I fixed that above.
One other thing. You will need to enable/disable the point light for the individual lights. To be more realistic, you may want to use a surface light instead, but that’s just a suggestion.
As for your original issue, is there a BoolValue named IsOn that is parented to ControlBox? Based on the error message that you are getting, that sounds like the problem.
In that case, what is the class of ControlBox? Can you provide a screenshot of your explorer window, and your properties window with ControlBox selected?