Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a NPC with head with hats move?

Asked by 4 years ago

The script I tried before was "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" Thank you all who help (This was already posted on the site by "cabbler" itake no credit for this script)

0
Please use code blocks for your entire script. User#32819 0 — 4y

Answer this question