Why is this putting a part into the player?

So I have a script and Im making a part to see where this raycast where fire to.
But there is a bug.

When ever I use this script it puts the part into the character and not 30 studs in front of it

Why is this happening?

		local origin = char.PrimaryPart.Position
		
		local rayDirection = origin + Vector3.new(CFrame.new(origin) * CFrame.new(30,0,0)) -- this is the position I need to send it to. Which should be in 30 studs in front
		
		local part = Instance.new('Part')
		part.Parent = workspace
		part.Anchored = true
		part.Position = rayDirection -- put the part where the position is 

30 studs infront would be:

CFrame.new(0, 0, 30)

You are putting it 30 studs to the right, not to the front.

Same thing. It is still appearing inside of the character

You might wanna do this:
If you have the character’s humanoid root part defined as hrp:
local rayDirection = origin + hrp.CFrame.LookVector * 30

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.