How to make a part spawn in front of a player's HumanoidRootPart by 2 studs?

Heu guys! I don’t know how to do this and I’m pretty sure it should be simple but I’ve been trying for some time can’t figure it out. I’m trying to make a sword projectile that spawns in front of the player’s HRP and move it 2 studs in front of them but I’ve tried some stuff and they won’t work.

Slash_Projectile_Clone.Position = Owner_HRP.Position + (Owner_HRP.CFrame.LookVector * 2)
Slash_Projectile_Clone.Position = Owner_HRP.Position + Vector3.new(0, 0, 2)
Slash_Projectile_Clone.CFrame = Owner_HRP.CFrame * CFrame.new(0, 0, 2)
Slash_Projectile_Clone.Orientation = Vector3.new(0, 90, 90)
2 Likes

There are two types of CFrame spaces, World space and Local space. If you want to place it relative to the humanoidrootpart’s direction (local space), you’ll need the * operator, for world space it’s the + operator. Try this:

Slash_Projectile_Clone.Position = Owner_HRP.Position * CFrame.new(0, 0, 2)

Correct me if I’m wrong, but instead of being between world space vs local space, I believe the * operator is for CFrame operations and the + is for vectors.

Try

humanoidRootPart.CFrame += humanoidRootPart.CFrame.LookVector

Tbh I don’t even know lol :joy: XD

Also, after testing, it appears that you can only perform this on the client because the server doesn’t have CFrame orientation data for the player? I don’t know why.

Wait what, that’s a server script

Hold on, I’m so confused. Server scripts don’t have the CFrame orientation data for the player? I never knew that

They should which is why I’m equally confused.

My test script (non-legacy client):

local Players = game:GetService("Players")
local player = Players.LocalPlayer

player.CharacterAdded:Connect(function(character: Model)
	while character do
		local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")

		humanoidRootPart.CFrame += humanoidRootPart.CFrame.LookVector * 2

		task.wait(0.05)
	end
end)

works but only on the client for some reason.

This post may be helpful but I don’t have enough time to read it

I’m still not sure how to even make this sword projectile in front of the player’s HRP ;-;

Slash_Projectile_Clone.CFrame = Owner_HRP.CFrame * CFrame.new(0, 0, -2) -- may have change this value a little

Normally I’d gave an explanation but I’m too tired right now, so Ill just say, you can can’t add a Vector and a CFrame, you can get the Vector of a CFrame by doing CFrame.Position. ok bbyeyeto

Not sure if I did it right but it also errored :thinking:

Slash_Projectile_Clone.CFrame = Owner_HRP.CFrame * CFrame.new(0, 0, -2).Position

Projectile.CFrame = HumanoidRootPart.CFrame * CFrame.new(0, 0, 2)

This will position and orient a part to the HumanoidRootPart, and offset it forwards by 2 studs. Hope this helps!

Remove the .Position on the end there.

Using .Position on the end of a CFrame will return a Vector3 of the part’s position. Doing * will only work on other CFrame values and not a Vector3.

CFrames are values that hold both position and rotation


That didn’t work ;-;

Could you share your full script? Cause this should successfully position and orient the part relative to your character model, you may have some other lines of code possibly interfering with it, otherwise i got no idea

I just realized I had this line of code that changes the part’s orientation but removing it still didn’t do anything

Is it the spawning thats the issue? Cause it looks like it correctly spawns in front of the player, but its just simply travelling in the wrong direction it appears