Attempt to index field 'Parent' (a nil value)

In my game sometimes, very rarely, a very curious error comes out that I don’t understand why it happens.

“Players.Player.PlayerGui.LobbyGui.Frames.Inventory.Inventory:67: attempt to index field ‘Parent’ (a nil value)” and “Players.Player.PlayerGui.LobbyGui.Frames.Shop.Shop:69: attempt to index field ‘Parent’ (a nil value)”

This error comes out in the script of the Inventory and Shop gui in exactly the same way.

local inventoryButton = frame.Parent.Parent:WaitForChild("Buttons"):WaitForChild("InventoryButton")
inventoryButton.MouseButton1Down:connect(otherButtonDown)

local shopButton = frame.Parent.Parent:WaitForChild("Buttons"):WaitForChild("ShopButton")
shopButton.MouseButton1Down:connect(otherButtonDown)

local spectateButton = frame.Parent.Parent:WaitForChild("Buttons"):WaitForChild("SpectateButton")
spectateButton.MouseButton1Down:connect(otherButtonDown)

local configButton = frame.Parent.Parent:WaitForChild("Buttons"):WaitForChild("ConfigButton") --ERROR
configButton.MouseButton1Down:connect(otherButtonDown)

That portion of the Script is in both the Inventory and Shop Script, and here is an image of the Explorer.
asd

The error comes out in the line with “local configButton”, what seems strange to me is that it doesn’t come out in the previous ones, which also have “script.Parent.Parent” but they works.

Does anyone know why this is happening? I’ve checked and the Parent is never changed.

You’re probably running into some sort of replication-lag. How are you defining frame? Is it defined using script.Parent or player.PlayerGui:WaitForChild()?

If it’s script.Parent, changing it to something like this might be a good idea.

local pg = game.Players.LocalPlayer:WaitForChild("PlayerGui")
local lobbyScreen = pg:WaitForChild("LobbyGui")
local frames = lobbyScreen:WaitForChild("Frames")
local frame = frames:WaitForChild("Inventory"):WaitForChild("Frame")

and then I would also change your frame.Parent.Parent references to frames

8 Likes

Can someone with appropriate permissions report this as a bug?
There’s no question that this is a bug: Scripts are only meant to run if they’re a descendant of certain game directories. Having a nil parent means it’s not a descendant.

By the way, the faster and simpler fix is just to disable ResetOnSpawn for the offending GUI, most GUIs don’t need to reset on spawn.

2 Likes

Can someone with appropriate permissions report this as a bug?

OP can use post approval procedure to file this as a bug!

2 Likes