"if not inst:FindFirstChild("") then return end" not working

So im trying to check if an instance exists, but

if not seat:FindFirstChild("Speakers") then return end

Doesn’t work and returns this error

attempt to index nil with 'FindFirstChild'

I’ve also tried

if seat:FindFirstChild("Speakers") and active == true

But it returns the same error

here’s some info if you need any:

“Speakers” is an Object Value (has a Value)
im using the Humanoid.Seated function
my script is located inside a LocalScript (idk if that effects anything)

:FindFirstChild() always works with my other scripts, but this one isnt working

If you need my code to help me, then here it is:

Player.Character.Humanoid.Seated:Connect(function(active, seat)
	if not seat:FindFirstChild("Speakers") then return end
	if seat:FindFirstChild("Speakers") and active == true--[[ and Player.Character.Humanoid.SeatPart:FindFirstChild("Speakers").Value ~= nil--]] then
		Gui.Visible = true
	elseif active == false then
		Gui.Visible = false
	end
end)

I’ve already tried looking on other Dev forums for help but i couldn’t find a fix

Any help is appreciated!!

1 Like

have you tried doing that using an “else if”?

if seat:FindFirstChild("Speakers") and active == true then
--do stuff
elseif not seat:FindFirstChild("Speakers") then
--do some other stuff
end

Yes, but i get the same error

I just tried your code and it errors out

2 Likes

I just tried it and it worked perfectly there might be a problem with the active variable then?

1 Like

attempt to index nil with 'FindFirstChild' means seat was nil

2 Likes

So do i need to check if active == true then continue?

2 Likes

no actually I think he is right there must be a problem with the seat

1 Like

You need to check if seat exists. The error happens any time a player gets out of a seat.

oh yeah, thanks for the help!!!
It works now

1 Like

tell us if it works or not after you check the seat

1 Like

yeah it works now, thanks for the help!!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.