Attempt to call a nil value

Can somebody please help me fix this script.

The script is placed into a GUI on a vehicle which when a button is pressed the vehicle doors “should open” but they don’t I have set this up in a similar way the keyboard controls are setup.

I have provided both the button version (where I’m getting the attempt to call a nil value error)
and the keyboard controls version (which works fine)

Button version (attempt to call nil value) - this is for mobile players

script.Parent.Parent.Parent.Parent.FE_Events.BusControls.OnServerEvent:connect(function(Car)

function Clicked() 
		Car.Main.HingeDoors.Open.Value = not Car.Main.HingeDoors.Open.Value
	end
end)

script.Parent.MouseButton1Click:connect(Clicked)

Keyboard controls version (works fine) - for PC/Xbox players [xbox controls are not show in the script however they are in the main script I have]

script.Parent.FE_Events.BusControls.OnServerEvent:connect(function(player, Car, exec)
	if exec == Enum.KeyCode.L then
		Car.Main.Headlights.Lit.Value = not Car.Main.Headlights.Lit.Value
	elseif exec == Enum.KeyCode.Z then
		Car.Main.HingeDoors.Open.Value = not Car.Main.HingeDoors.Open.Value
	end
end)

As you can see they are basically the same the only difference is one is controlled by keyboard/controller input the other is controlled by buttons on a GUI but sadly the GUI button one doesn’t work.

Appreciate any help

Sorry if this sounds all confusing.

That top script can’t be right, because you don’t even end the function on the first line. It would get a compile error. Can you please show the full script on the top and add a comment so I know which line the error is on? Thanks.

The bottom line of code does not work because the function definition is in another scope. Try moving the function definition outside of the scope.

script.Parent.Parent.Parent.Parent.FE_Events.BusControls.OnServerEvent:connect(function(Car)
    -- There's nothing here.
end)
function Clicked()
	Car.Main.HingeDoors.Open.Value = not Car.Main.HingeDoors.Open.Value
end
script.Parent.MouseButton1Click:connect(Clicked)

However, the fact that you’ve opened the door will not replicate to the server.
Perhaps you wanted:

script.Parent.Parent.Parent.Parent.FE_Events.BusControls.OnServerEvent:connect(function(Car)
    Car.Main.HingeDoors.Open.Value = not Car.Main.HingeDoors.Open.Value
end)
function Clicked()
	-- Put code here to tell the server that you've opened the door.
end
script.Parent.MouseButton1Click:connect(Clicked)

the top one is the full script.