Script doesn't index(?) image labels when asked to turn it visible and invisible

I’m trying to make arrow images on a Gui turn on and off whenever the signal value is toggled by the script. I am using A-Chassis (but that shouldn’t be part of the issue.)

I keep getting this error:

Piece of script that I thought would turn the image labels visible and invisible:

script.Parent:FindFirstChild("kjVehicleGui").LeftTurn = false
script.Parent:FindFirstChild("kjVehicleGui").RightTurn = false
while true do
	wait(0.5)
	if vals.Leftsignal == true then
		script.Parent:FindFirstChild("kjVehicleGui").LeftTurn = true
		script.Parent:FindFirstChild("kjVehicleGui").TurnOff:Play()
		wait(0.35)
		
		script.Parent:FindFirstChild("kjVehicleGui").LeftTurn = false
		script.Parent:FindFirstChild("kjVehicleGui").TurnOn:Play()
		wait(0.35)
	else
		script.Parent:FindFirstChild("kjVehicleGui").LeftTurn = false
	end
	
	if vals.Rightsignal == true then
		script.Parent:FindFirstChild("kjVehicleGui").RightTurn = true
		script.Parent:FindFirstChild("kjVehicleGui").TurnOff:Play()
		wait(0.35)
		
		script.Parent:FindFirstChild("kjVehicleGui").RightTurn = false
		script.Parent:FindFirstChild("kjVehicleGui").TurnOn:Play()
		wait(0.35)
	else
		script.Parent:FindFirstChild("kjVehicleGui").RightTurn = false
	end
end
1 Like

This is where the arrow image labels are.
image

One thing that I see right now are that you should put Visible after LeftTurn and RightTurn in your script and is your mentioned script inside of kjVehicleGui?

Oh. I forgot, I make that mistake a lot, thanks for looking out for thag. No the mentioned script is not. The script and gui are both child’s of a parent.

I hope that’s the solution for your problem.

It is not. I edited the script so it actually changes the .visible property but the script still fails to find the image label.

Piece of code:

script.Parent:FindFirstChild(“kjVehicleGui”).LeftTurn = false
script.Parent:FindFirstChild(“kjVehicleGui”).RightTurn = false
while true do
wait(0.5)
if vals.Leftsignal == true then
script.Parent:FindFirstChild(“kjVehicleGui”).LeftTurn.Visible = true
script.Parent:FindFirstChild(“kjVehicleGui”).TurnOff:Play()
wait(0.35)

  script.Parent:FindFirstChild("kjVehicleGui").LeftTurn.Visible = false
  script.Parent:FindFirstChild("kjVehicleGui").TurnOn:Play()
  wait(0.35)

else
script.Parent:FindFirstChild(“kjVehicleGui”).LeftTurn.Visible = false
end

if vals.Rightsignal == true then
script.Parent:FindFirstChild(“kjVehicleGui”).RightTurn.Visible = true
script.Parent:FindFirstChild(“kjVehicleGui”).TurnOff:Play()
wait(0.35)

  script.Parent:FindFirstChild("kjVehicleGui").RightTurn.Visible = false
  script.Parent:FindFirstChild("kjVehicleGui").TurnOn:Play()
  wait(0.35)

else
script.Parent:FindFirstChild(“kjVehicleGui”).RightTurn.Visible = false
end
end

The snippet is located in the VehicleLights local script and at the very bottom of it.

Folder containing both the script and Gui:
image

At runtime, loading the playergui can take some time, so when trying to get any child of a gui at the beginning of runtime, you should use :WaitForChild()

If this gives you a warning after 5 or so seconds, let me know.

I replaced all the :FindFirstChild() within the snippet to :WaitForChild() and it still continues to give the same error.

I am specifically referring to when you do .LeftTurn.Visible = false, or .TurnOff:Play(), which should be replaced by :WaitForChild("LeftTurn").Visible = false, and :WaitForChild("TurnOff"):Play(), respectively.

I also recommend creating variables for leftTurn, rightTurn, ajnd turnOff, so you would have:

local gui = script.Parent:WaitForChild("kjVehicleGui")
local leftTurn = gui:WaitForChild("LeftTurn")
local rightTurn = gui:WaitForChild("RightTurn")
local turnOff = gui:WaitForChild("TurnOff")

leftTurn.Visible = false
rightTurn.Visible = false
while true do
	wait(0.5)
	if vals.Leftsignal == true then
		leftTurn.Visible = true
		turnOff:Play()
		wait(0.35)
		
		leftTurn.Visible = false
		turnOn:Play()
		wait(0.35)
	else
		leftTurn.Visible = false
	end
	
	if vals.Rightsignal == true then
		rightTurn.Visible = true
		turnOff:Play()
		wait(0.35)
		
		rightTurn.Visible = false
		turnOn:Play()
		wait(0.35)
	else
		rightTurn.Visible = false
	end
end
1 Like