Issue with :Destroy() for destroying SpecialMesh

Hi everyone!

I have very little scripting knowledge, so I welcome any help and apologize if I use the wrong terms to describe my issue!

The game I work on uses :Destroy() in the Avatar Editor to change your player’s head, i.e., it destroys the previous head so a new one can replace it. This function used to work, however, after moving the map to a “New Place”, it doesn’t work anymore.

Here is a screenshot of the lines of code that the error refers to:

Here is the error message you get when you try to change your head with the Avatar Editor:

ServerScriptService.Avatar:868: attempt to index nil with 'Destroy' - Server - Avatar:868

Any help is much appreciated and I’m very happy to share more details! Thanks.

Questions:

  • Is There a SpecialMesh?

  • Have you tried using FindFirstChild or WaitForChild?

  • Does the object exist when running?

  • Are you getting the Correct Istance?

Check that the object exists

local Mesh = newHead:FindFirstChildOfClass("SpecialMesh")
if Mesh then		Mesh:Destroy()			end

Also, some heads don’t use SpecialMesh, so consider using HumanoidDescription or better verification.

local HD = humanoid:GetAppliedDescription():Clone()
HD.Head = 0 --> New head id
humanoid:ApplyDescription(HD)
HD:Destroy()
1 Like