How to correctly parent shit to attachment points?

function CreateHeadOnSpawn( ply )
local prev_head = ply:GetNWEntity( “head” )

local eyeAttachID = ply:LookupAttachment( "eyes" )
local eyeAngPos = ply:GetAttachment( eyeAttachID )
local eyeAng = ( eyeAngPos.Ang:Right() * -1 ):Angle()
local eyePos = eyeAngPos.Pos - eyeAng:Up()*25 - eyeAng:Forward()*6

if ply:GetNWEntity("phys_head"):IsValid() then

if prev_head:IsValid() then
	if prev_head:GetParent() != ply then
		prev_head:SetParent( ply )
		prev_head:SetPos( eyePos )
		prev_head:SetAngles( eyeAng )
		prev_head:Fire( "SetParentAttachmentMaintainOffset", "eyes", 0.01 )
	local head = ents.Create( "prop_dynamic" )
	head:SetModel( "models/Gibs/antlion_worker_gibs_head.mdl" )
	head:SetParent( ply )
	head:SetPos( eyePos )
	head:SetAngles( eyeAng )
	head:Fire( "SetParentAttachmentMaintainOffset", "eyes", 0.01 )
	head:SetCollisionGroup( COLLISION_GROUP_DEBRIS )
	ply:SetNWEntity( "head", head )

hook.Add( “PlayerSpawn”, “CreateHeadOnSpawn”, CreateHeadOnSpawn )

function GetPlayerHeadPosAndVelocityOnDeath( prey, pred, dinfo )
local head = prey:GetNWEntity( “head” )

if head:IsValid() then
	prey:SetNWVector( "death_head_pos", head:GetPos() )
	prey:SetNWVector( "death_head_ang", head:GetAngles() )

prey:SetNWVector( "death_vel", prey:GetPhysicsObject():GetVelocity() )

hook.Add( “DoPlayerDeath”, “GetPlayerHeadPosAndVelocityOnDeath”, GetPlayerHeadPosAndVelocityOnDeath )

function DetachHeadFromRagdollOnDeath( prey, pred, dinfo )
local head = prey:GetNWEntity( “head” )
local headPos = prey:GetNWVector( “death_head_pos” )
local headAng = prey:GetNWVector( “death_head_ang” )

if head:IsValid() then
	local phys_head = ents.Create("prop_physics")
	phys_head:SetModel( "models/Gibs/antlion_worker_gibs_head.mdl" )
	if headAng != nil then
		phys_head:SetAngles( headAng )
	if headPos != nil then
		phys_head:SetPos( headPos )
		phys_head:SetPos( prey:GetPos() + Vector(0,0,32) )
	phys_head:SetMoveType( MOVETYPE_VPHYSICS )
	phys_head:SetCollisionGroup( COLLISION_GROUP_DEBRIS )
	local preyDeathVel = prey:GetNWVector( "death_vel" )
	if preyDeathVel != nil then
		phys_head:GetPhysicsObject():SetVelocity( preyDeathVel )
	prey:SetNWEntity( "phys_head", phys_head )

hook.Add( “PlayerDeath”, “DetachHeadFromRagdollOnDeath”, DetachHeadFromRagdollOnDeath )

I’m trying to make it so that all players get antlion worker heads. To do that, I know you have to parent it to the head’s attachment point. To do that, you have to parent it to the player, then fire the input SetParentAttachmentMaintainOffset. However, for some reason which I can’t seem to understand, when I parent the antlion head to the player the position gets fucked up. It’s different every time! No matter what order I put SetPos and SetParent in, it still gets fucked up. I even tried using a timer to delay the parenting, but still no dice. It’s really, really frustrating not to be able to do something this mundane. Does anyone have any ideas? I know that expression 2 has the same problem when trying to parent holograms to player’s heads. Is it just not possible to make code that parents things to attachment points reliably?

Sorry to bump, but this is relatively important. I mean, my gamemode is called “Ants” anyway…I want them to look like ants. Or, at least their heads…


bump. I have the exact same problem

bump, same I need the answer to this!!!