How can I make the part spawn 2 studs in front of the player?

As you can see from the title, I’m trying to make a part spawn in front of a player (and it’s going to be welded to the player so it moves with them) and I have a sort of functional script except it doesn’t rotate to the player’s rotation it starts to mess up weirdly when i try to modify it with Vector3.new or CFrame.new, all help would be appreciated.

here’s my code:

local replicatedStorage = game:GetService("ReplicatedStorage")

	replicatedStorage.WandaRemotes.WandaShield.OnServerEvent:Connect(function(player)
		local character = player.Character

		local shield = replicatedStorage.WandaPowers.WandaShield:Clone()

		local weldConstraint = Instance.new("WeldConstraint")
		weldConstraint.Part0 = shield
		weldConstraint.Part1 = character.HumanoidRootPart
		weldConstraint.Parent = shield

		shield.Position = character.HumanoidRootPart.Position + character.HumanoidRootPart.CFrame.LookVector
		shield.Parent = workspace
	end)
1 Like

Maybe don’t use CFrame.LookVector. One thing to note is that a part’s front surface is always the negative Z direction (-Z), so you can do this instead:

shield.Position = character.HumanoidRootPart.Position + Vector3.new(0, 0, -2)

^ Is a really good comment, however it’s not going to be relative to the characters orientation, To do this you’re going to need to utilise CFrames. (Just to orientate it!)
https://gyazo.com/45cfa5f21b5b00e33e02288073fba1c4

shield.CFrame = character.HumanoidRootPart.CFrame * CFrame.new(0, 0, -2)
1 Like

just so I understand correctly, using CFrame make it relative to the orientation? (it works btw i just wanna make sure)

Unfortunately, I don’t think WeldConstraints have the CFrame property.

no no, the shield is a part, the weld just keeps it on the player

1 Like

Oh, then I’m mistaken. You can use the CFrame then. Set the shield’s CFrame the same as the HumanoidRootPart.

1 Like

yeah; CFrame contains ALOT of information covering a series of things such as look, orientation and position. You can learn much more about it here, Roblox made an awesome tutorial for it!

1 Like