Attempt to index nil with 'Parent' [SOLVED]

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I want to get the ancestor of script.

  1. What is the issue? Include screenshots / videos if possible!

  2. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I tried to use all of the FindFirstAncestor method but it didn’t work.

local Model = script.Parent.Parent.Parent

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

either script.Parent.Parent or script.Parent.Parent.Parent is nil. Check during runtime to make sure.

I try it but when i use a new method like FindFirstAncestor and i run the script for a first time the error didn’t occur but at the second time the error will occur and it’s actually return nil

image

The dropper probably got destroyed. Check if there is anything destroying it.

Can you show us the script in the Explorer and its ancestors as well so we can see where it’s located, please?

image

1 Like

oh i destroy the dropper but how can i fix it? i really have no clue about it.

Since there’s a chance the dropper is destroyed you’ll need to use an if statement before running the rest of the script:

local dropper = script.Parent

if dropper then
	local tycoon = dropper:FindFirstAncestor("Tycoon")

	if tycoon then
		-- Safe to run the rest of your script inside here, example:
		print(true)
	else
		warn("Tycoon is nil")
	end
else
	warn("Dropper is nil")
end
1 Like

I really appreciate you and thank you so much sir!

1 Like

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