How do I make a part (head) follow my character (for a horror game)

Ok. so. I want to make a horror game where there will be parts that follow your character (lets say a head) it’s kinda hard to explain so here are some photos:
image image image
So yeah, I kinda need help with a script that makes a part rotate and like get locked onto your avatar but then locks onto other people too so not just you.

heres a gif
https://gyazo.com/848539042945864b72069b98843f5cc6

the game is here so you can see what i REALLY mean for yourself:

and the stud guy also follows you with its head from like across the map too if you’re the only one in the server.

i currently have:

local radius=20
local npc = script.Parent
local head = npc:WaitForChild('Head')

local function rotationDifference(oldCF,newCF)
    --self explanatory
    return (newCF.lookVector - oldCF.lookVector).magnitude
end

while wait(1) do
    --loop through characters
    local cf = head.CFrame
    local p = cf.p

    for _,player in pairs(game.Players:GetPlayers()) do
        local char = player.Character
        if char then
            local ppart = char.PrimaryPart
            if ppart then

                local pos = ppart.Position
                local isInRadius = (pos-p).magnitude < radius
                if isInRadius then
                    --found close character
                    if rotationDifference(cf , CFrame.new(p,pos)) < 1.25 then
                        --character is in front

                        --look at character until it leaves or goes behind
                        repeat
                            p = head.Position
                            pos = ppart.Position
                            head.CFrame = CFrame.new(p,pos)
                            wait(1/20)
                        until ( (pos-p).magnitude > radius ) or ( rotationDifference(cf , head.CFrame ) > 1.25 )
                        head.CFrame = (cf-cf.p)+p --old rotation
                        break
                    end
                end
            end
        end
    end
end

any help would be appreciated, basically i just kinda need help with the script that the part has inside of it…

thanks for reading

1 Like

If you want it to be hovering, you should remove its gravity.
Use tween to make the movement smoother.

local tween= game:GetService('TweenService')
local move= tween:Create(Head,TweenInfo.new(1),{Position=ppart.Position})
move:Play()
1 Like

Still needing help with this…

1 Like

This is not my game or model or anything, but i had it saved from some time ago

But it might help!!

5 Likes