Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My script saying attempt to index field 'Parent' (a nil value)? (Answered)

In the script, I was using parent kinda lot but not sure if thats the issue or not. This gui was in the lighting, and it also trying to delete a frame that was in the lighting. The items are in place though, so idk why it's not working. I dont think I have ever got this error before. Here's my code:

local event = game.ReplicatedStorage.ClosedEvent
event.OnServerEvent:Connect(function()
	script.Parent.Parent.Parent:Destroy()
	script.Parent.Parent.Parent.Parent.ActiveLobbys.Frame.Frame.Frame:Destroy()
end)

1 answer

So, I changed my code a little, thanks to Twinbropotato. I wasn't really paying attention, I was destroying it before it could destroy the other object. I'm not sure why it said the parent error though, so I made a variable for the parents. Code:

local event = game.ReplicatedStorage.ClosedEvent
local parent2 = script.Parent.Parent.Parent.Parent
event.OnServerEvent:Connect(function()
	parent2.ActiveLobbys.Frame.Frame.Frame:Destroy()
	script.Parent.Parent.Parent:Destroy()
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.