trying to get a NPC's head to follow the player and also be able to animate/move. however, when i use this script, the entire body moves (the head is bound to the torso, is that an issue? i don't think so) instead of just the head and the NPC cannot move or animate. "look" is used to default NPC back to position. this may be the issue, as it must default to look a certain direction, but clarification would be sweet.

stats for bodygyro: D = 350, MaxTorque = 2000,2000,2000, P = 3000

stats for bodyposition: D = 1250, MaxForce = 4000,4000,4000, P = 10000, and Position = 0,50,0.

script is below.

local head = script.Parent.Parent.Head
local bgyro = head.BodyGyro
local bposition = head.BodyPosition
local studsaway = 15
local look = game.Workspace.PellyLook

bposition.Position = head.CFrame.p

while wait() do
	for _, v in pairs(game.Players:GetPlayers()) do
		local character = workspace:WaitForChild(v.Name)
		if character then
			local distance = (head.CFrame.p - character.PrimaryPart.CFrame.p).Magnitude
			if distance <= studsaway then
				bgyro.CFrame = CFrame.new(head.CFrame.p, character.PrimaryPart.CFrame.p)
				break
			else
				bgyro.CFrame = CFrame.new(head.CFrame.p, look.CFrame.p)
			end
		end
	end
end

8 comments

0

Line 11 will error if a player named Part joins the game LOL

0

well i'm glad nobody named Part is going to join the game

0

No, I'm saying if you have a part just named "Part" in the workspace it will error

0

i've got a part named "Part" in the workspace and i am not getting any errors. everything works same as before.

0

If a player is named like something stored in workspace (e.g "Part" like incapaz says) it will error

0

use "v.Character or v.CharacterAdded:Wait()" instead

0

Ye

0

ah, understood. still not solving my issue though.