Getting an NPC to follow a player

I am trying to get a npc to follow me using ai_goal_follow

But I am not familiar with this entity so I have not been able to get it to work so far.
I have tried it in dozens of combinations with no success.


	local res = ply:GetEyeTrace()
	
	
	-- Create the npc and spawn it at my view
	ent = ents.Create("npc_alyx")
	ent:SetKeyValue("name", "cunt") -- for the actor to affect attribute
	ent:SetPos(res.HitPos) 
	ent:Spawn()
	
	
	-- Make her friendly for the target entity option
	ent:AddEntityRelationship(ply, D_LI, 999)
	
	
	-- Set the name on myself
	ply:SetKeyValue("name", "fuck")
	
	
	-- Create the follow entity
	ent = ents.Create("ai_goal_follow")
	ent:SetKeyValue("maximumstate", "2")
	ent:SetKeyValue("formation", "0")
	ent:SetKeyValue("targetentity", "fuck") -- Should follow me
	ent:SetKeyValue("actorstoaffect", "cunt") -- Using the npc I just created 
	ent:SetKeyValue("startactive", "1")
	ent:SetKeyValue("searchtype", "0")
	
	ent:Spawn()
	ent:Activate()

There is actually a tool for this, you don’t really need a code, if you want to have the code, I’m sure somebody can still help you,

Here’s the tool for it.

I’m not looking for a premade tool.

You know, you could view the tool’s lua code, and then use what you need…

Is only available in the workshop which gets downloaded into a gma file and its a pain in the ass to try and unpack.

I took it apart and it seems to use SetSchedule and SetLastPosition. Neither work for me.