Parent seemingly nil. A rift in the spacetime continuum? Please help

As far as I am aware, you can not have a parent that is nil. Unless…

But with the following code I’m getting an error explainable if that were the case:

LOCAL SCRIPT:

local function isShip(whatever)
	return string.find(string.lower(whatever.Name),"ship") and whatever:FindFirstChild("Weld")
end

local function findFirstAncestor(descendant, callback)
	while not callback(descendant) do
		if descendant == game then return nil end
		descendant = descendant.Parent
	end

	return descendant
end

local m = findFirstAncestor(script,isShipNamed)

is erroring saying .Name is not a valid member of nil/whatever

How could this be the case? It can only be in the game, what is actually going on?

P.S. This is during running 6 players in a local test on my laptop; one of the client simulations throws it. If something isn’t WaitForChild, you’re going to hear it, it’s uber-tardy at that amount.

All your function does is replicate the FindFirstAncestor function, is there any reason why you don’t just resort to using FindFirstAncestor?

Regardless, a simple sanity check should solve your issue here:

local function isShip(whatever)
	if whatever then
		return string.find(string.lower(whatever.Name),"ship") and whatever:FindFirstChild("Weld")
	else
		return nil
	end	
end
1 Like