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

How do I fix parent property locked error?

I am trying to make it so that when I equip "The wizard staff " a gui will appear on the users screen and when they unequipped it the gui shall disappear. I am firing the server with an event. The problem arrives after gui appears and disappears. When the event triggers a third time I get the error: The Parent property of WizardStaffGui is locked, current parent: NULL, new parent PlayerGui

Here is the relevant code

local WizardStaffGui = game.ServerStorage.Guis.WizardStaffGui:Clone()


game.ReplicatedStorage.WizardStaffGui.OnServerEvent:Connect(function(player)
	
	if player.PlayerGui:FindFirstChild("WizardStaffGui") == nil then
		WizardStaffGui.Parent = player.PlayerGui
		
		
	else
		player.PlayerGui:FindFirstChild("WizardStaffGui"):Destroy()
		
		
	end
	
	
end)

1 answer

✓ Accepted answer

#Reasoning


The first time this Signal fires, it will place it in the PlayerGui. The second time it will "remove" the GUI. The third time, it tries to set something that doesn't exist. This is because you destroyed it.

This is why you're getting the error. Your’re trying to set the Parent of something that you destroyed. This means it no longer has a Parent, as it doesn’t exist anymore. Locked means the Parent property is inaccessible, ergo NULL.


#Solution


:Destroy() is predominantly for the use of destroying and Object as you don’t need anymore. If you want to remove something and put it back, set it’s Parent to nil, so it will appear as it’s gone, though just isn’t situated anywhere, once reparented, it’ll be usable again. - Do this for lines 11.


Hope this helps, don’t forget to accept this answer if so!

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