Attempt to index nil with parent but it found the parent?

for some reason I’m getting the error “attempt to index nil with parent” on line 9 even though line 9 worked (the black hole was put in the workspace.)

Code:
Screen Shot 2022-08-24 at 2.10.59 PM

Error:

Proof the object exists:
Screen Shot 2022-08-24 at 2.11.19 PM

1 Like

What are you trying to do here? Set the BlackHole’s parent to ServerStorage? Why do you need to do that?

I’m trying to put the black hole in the workspace as seen in line 9. (ignore line 22)

line 9:

game.ServerStorage.EventModels:FindFirstChild("BlackHoleItem").Parent = workspace

Wait what, then why is the name different this time from BlackHole to BlackHoleItem

I said ignore line 22. I accidentally wrote line 22 wrong. But line 9 is the one erroring.

How would I know which line… Just copy and paste which is the code that’s giving an error.

this is the code.

30 lettersss

1 Like

Sorry I’m dumb, have you tried WaitForChild()?

What kind of script is this, keep in mind local scripts don’t have access to ServerStorage!

You are attempting to find the property called Parent which doesn’t exist since FindFirstChild returns nil if it doesn’t find it. Have you checked if BlackholeItem actually exists in ServerStorage?

its a normal script, not a local script.

Screen Shot 2022-08-24 at 2.11.19 PM

Strange. Have you tried printing the object in the output see if it works?

print(game.ServerStorage.EventModels:FindFirstChild("BlackHoleItem"))

it prints fine.
Screen Shot 2022-08-24 at 3.10.22 PM

of course its gonna print the item its on run, you need to use WaitForChild(“BlackHoleItem”) because the object still does not exist, its loading.

Edit: If it still gives an error something like attempt to index nil with WaitForChild; the parent is still loading.

I see the problem, it is a while loop so when you parent it to workspace in the first loop, it is no longer in server storage. Then in the second loop, it cannot find BlackHoleItem, thus errors.

1 Like

Instead of this:

game.ServerStorage.EventModels:FindFirstChild("BlackHoleItem").Parent = workspace

Can’t you just do this for line 9, Isn’t that the same thing?

game.ServerStorage.EventModels = workspace

That would bring all the models that are stored inside that folder so no, it is not the same thing.

However EventModels Children BlackHoleItem’s Parent is Event Models

Correct, and what the code does is change its parent to workspace.