How to make CFrame part rotate by player moving?

Hello! I was making CFrame script which makes part be facing toward local player’s humanoidrootpart. In short the part has certain position, but it changes its rotation when player moves. Here is the script i wrote:

local player = game.Players.LocalPlayer
local character = player.Character
local part = game.Workspace.Part
local hum = character:WaitForChild("HumanoidRootPart")
local partpos = Vector3.new(-0.58, 7.769, -10.775)
local parttarpos = hum.Position

while wait() do
	part.CFrame = CFrame.new(partpos, parttarpos)
end

But when I launch test, part just stuck its front side to the top like this:
front

How to make it change its rotation by player moving?

Also for CFrame script I used this roblox article.

3 Likes

thats because you defined the position value, so it wont change at all
use the hum.Position directly in the loop for it to work

fix:
while wait() do
part.CFrame = CFrame.new(partpos, hum.Position)
end

3 Likes