How am I able to always have a part in front of a player by about 10 studs?

Hi DevForum! So I tried making a script on how to always keep a part in front of a player by 10 studs, ( or any amount it doesn’t matter) but the script I have isn’t working. I know it has something to do with LookVector, but I just can’t figure out how to go about it.

Note that this is only for testing purposes in a local script.

Here is my script:

local arrowpart = workspace.ArrowPart
local player = game.Players.LocalPlayer
local character = player.Character

while true do
	arrowpart.Position = character.HumanoidRootPart.CFrame.LookVector * 10
	wait()
end
local arrowpart = workspace.ArrowPart
local player = game.Players.LocalPlayer
local character = player.Character
local HumanoidRootPart = character:WaitForChild("HumanoidRootPart")

while true do
	arrowpart.Position = HumanoidRootPart.Position + HumanoidRootPart.CFrame.LookVector * 10
	wait()
end

Explanation:
LookVector is a Vector3 that describes which way does the part face, so it doesn’t account for position of the object, which is why you will need to add the LookVector multiplied by 10 to the position

2 Likes

Hi Fvrenight!

This is verry easy to do:
(dont copy my code cause i didnt tested it)

local player = game.Players.LocalPlayer
local object = Instance.new()

while true do
  wait(0.001)  -- to prevent script exhaustion
  object.CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,10) -- adjust offset here
end

hope it works :>

2 Likes

Thank you both for your replies, I appreciate it!