Attempt To Index Nil With "Parent"

I’ve run into this issue with this very simple script that I can’t seem to wrap my head around. I can easily go around the problem but I just want to understand what’s going on here.

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local cashTableBoughtEvent = ReplicatedStorage.CashTableBought
local bank = script.Parent.Parent.Parent.Parent

print("Event called")
cashTableBoughtEvent:Fire(bank)

The error in the output is:
Workspace.Banks.Bank1.Vault.Table.Button.EventFireScript:4: attempt to index nil with ‘Parent’

Here I just have a script that’s disabled. It is later enabled and it is meant to fire a remote event. But it just doesn’t like to use the term Parent. I’ve tried replacing line 4 with “local bank = workspace.Banks.Bank1” (getting the instance through the workspace instead of from the script) and it works just fine. Why did Studio react this way? Did roblox do something to the Parent keyword or what?

Have you tried using WaitForChild()?

local bank = workspace:WaitForChild("Banks").Bank1

I’ve found that I’ve deleted the Parent of the object, so the value of one of the Parents is missing. Very tricky bit of code there. I’ll revise everything so that it doesn’t jump through hoops like that.

Nope, thats not the issue my guy. Read the post next time

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