Making object that is always in front of the player not lag

I am making an object that is always in front of the player.


As you can see, the object lags, because there is a wait() in the following script which makes it stay in front of the player.

while true do
	wait()
	local newCFrame = CFrame.Angles(0, 0,math.rad(90))
	local offset = Vector3.new(0, 0.5,-5)

	clone.WoodDoor:SetPrimaryPartCFrame(character.HumanoidRootPart.CFrame*CFrame.new(offset)) 
	clone.WoodDoor:SetPrimaryPartCFrame(clone.WoodDoor:GetPrimaryPartCFrame() * newCFrame)

end

My question is: How do I make the movement of the object seamless?

You can just weld it to the humanoid root part with an offset, and it will without any additional scripts or lags or loops stay in front of the player. If you the part to not change orientation with humanoid root part, you can instead weld an invisible part to humanoid root part, and then use align position, to align this part with that part

use task.wait() instead of wait() since this runs on a higher frequency, secondly make sure its in a local script and not a server script, since players are locally simulated and have a network update delay to the server

1 Like

I’m guessing this is a server script. The lag/delay is caused by the ping. If you made this on a local script there shouldn’t be any delay. Then to place the object send the signal to a server script.

2 Likes