How to Make Part Spawn Exact Same Spot Every Time

Script:

		local NHead = Head:Clone()
		NHead.Parent = game.Workspace
		game.Debris:AddItem(NHead,15)

		NHead.CFrame = Char.HumanoidRootPart.CFrame * CFrame.new(0,5,-6) * CFrame.Angles(math.rad(0),math.rad(0),math.rad(0))

Question: I use this script to make the part spawn 6 studs in front of the player in whatever direction it looking. If the player is looking down then the part would spawn below the ground.

I was wondering if there was any way to make it spawn exactly in front of the player every time no matter where the player is looking. Since my game has a lot of ragdoll and combat this can cause lot of bugs in the combat.

1 Like

Try this

NHead.CFrame = Char.HumanoidRootPart.CFrame * (Char.HumanoiRootPart.CFrame.LookVector*6)

1 Like

Weird, when I used it this error kept popping up

22:40:48.454 HumanoiRootPart is not a valid member of Model

Convert rootpart lookvector into a unit vector (magnitude of 1) with the Y component removed so it doesn’t go underground, then multiply that unit vector by 6 so you have a vector of magnitude of 6 (6 studs in front of the player)

NHead.CFrame = Char.HumanoidRootPart.CFrame + ((Char.HumanoidRootPart.CFrame.LookVector * Vector3.new(1, 0, 1)).Unit * 6) + Vector3.new(0, 5, 0)
2 Likes

He made a typo when spelling HumanoidRootPart.

This worked I’ll test with flinging and more. So for it works very well. Thanks