parent prop to player

I am trying to create a script that parents an entity that I made to a players head, but how do I exactly do that?
I got slightly confused by the wiki so I hope someone can clear this up for me

I got this so far:

local function init()
	local test = ents.Create("ent_test")
	if ( !IsValid( test ) ) then return end 
	test:SetMoveType( MOVETYPE_NONE )
     for k, v in pairs(player.GetAll()) do
        test:SetParent() // what now :/
hook.Add( "Initialize", "xoxo", init )

Basically what i am trying to achieve here is, that whenever a player joins he gets a prop attached to him

GM:PlayerSpawn or

GM:PlayerInitialSpawn, parent the entity to the player argument

Entity:SetParent - Parent entity and, optionally, attachment id, must be specified.

I never really worked with entities, but from what I can see you should do [lua]local plr = Player(1) – Get a player from somewhere

local myEnt = ents.Create(“some entity”)
myEnt:SetParent(plr)[/lua]or something like this.

And what exactly are you trying to achieve by iterating through all the players?

Yeah I got that far already, I think I am only stuck at the parenting part

I just figured as much, looping here is pretty useless.
I still dont grasp the way of parenting the ent to the player though

You just do this in one of the hooks I gave you, assuming the argument is called “ply”

If you don’t know how hooks work, I recommend you read this:

hook.Add( "PlayerSpawn", "xoxo", function(ply)
	local test = ents.Create("ent_test")

	if ( !IsValid( test ) ) then return end 

	     test:SetMoveType( MOVETYPE_NONE )
	     test:SetParent(ply, 6)


But the script doesnt know where to attach it to now does it? And I feel like I am missing something here

EDIT: So I add a boneID I get it, but after adding like number 6 after ply it still doesnt appear? What am I doing wrong?

You need to call :Spawn() after creating an entity. It’s shown in the example of this, not sure how you missed it:


And I have that in my code, its not appearing

Show the code of your ent_test

You don’t use bone ID, you use attachment ID, here’s a list:

id	=	1
name	=	eyes
id	=	2
name	=	lefteye
id	=	3
name	=	righteye
id	=	4
name	=	nose
id	=	5
name	=	mouth
id	=	6
name	=	tie
id	=	7
name	=	pen
id	=	8
name	=	chest
id	=	9
name	=	hips
id	=	10
name	=	lefthand
id	=	11
name	=	righthand
id	=	12
name	=	forward
id	=	13
name	=	anim_attachment_RH
id	=	14
name	=	anim_attachment_LH
id	=	15
name	=	anim_attachment_head

But if I were you I’d use something like


just as an example.

Also you should first set the position of the entity to wherever you want it to be placed, try something like this:

mouthAtt = test:LookupAttachment("mouth")
tab = test:GetAttachment(mouthAtt)

pos = tab.Pos
ang = tab.Ang


AAAAND make sure it has no collisions or it will block the player.

Shouldnt I be looking for the players attachment?

Its just a basic entity with no properties, it spawns just a prop

If you are expecting something like a hat or backpack being attached to a player, then this is not for you
This will attach a prop into the player, but it will cause issues like collisions and that problems

Can you suggest a better way to do this? I dont really want to buy or use pointshop addons

Try drawing the model clientside on the client.


Draw the model there, also you can read how pointshop actually draw models into players, but there’s no a prop parenting functionallity, it’s just running drawmodel and applying position inside that hook