How to make my NPC face a player's head and shoot?

Like aimlock, how can my NPC face a player’s head and shoot? I tried this but it just doesn’t work. My NPC started stuttering and keeps ragdolling for some reason.

Epitaph is 0.187
targetplr is the target
Zombie is self-explanatory, the NPC.

local Future = targetplr.HumanoidRootPart.CFrame + (targetplr.HumanoidRootPart.Velocity * Epitaph + Vector3.new(0, .1, 0))
					Zombie.PrimaryPart.CFrame = CFrame.lookAt(Zombie.PrimaryPart.CFrame.Position, Future.Position)
2 Likes

hey h_h what do you mean by that? like what you need

like the NPC faces to another player’s head

Pathfinder is the NPC and the Noob is just a target for the pathfinder.
Red line determines what the Pathfinder is looking at

so if its moving then it will keep facing to the target (it will change target because it targets the closest target)

i think i understand how
try maybe
while true do
and put you’re code or i’ll try making these code ill give you one

i already tried that and if u dont understand heres the big code:

local TargetNonPlayers = true
local TargetType = 2
local Epitaph = .187

--[[
Target Type:
	Melee - 1
	Ranged - 2
Epitaph: Bigger = Higher Prediction
]]--

local Zombie = script.Parent
local PFS = game:GetService("PathfindingService")
local path = PFS:CreatePath()
local waypoints
local debounce = false

local function ConnectedWithAnchoredParts(Part)
	spawn(function()
		for _, parts in pairs(Part:GetConnectedParts(true)) do
			if parts.Anchored then
				return true
			end
		end
		return false
	end)
end

for _, part in pairs(Zombie:GetDescendants()) do
	if part:IsA('BasePart') and part.Anchored == false and not ConnectedWithAnchoredParts(part) then
		part:SetNetworkOwner(nil)
	end
end

local function FindTarget()
	local Target
	local TargetDistance = math.huge
	if TargetNonPlayers == false then
		for i, player in pairs(game:GetService('Players'):GetPlayers()) do
			local char = player.Character or player.CharacterAdded:Wait()
			if char:FindFirstChild('HumanoidRootPart') then
				local mag = (Zombie.HumanoidRootPart.Position - char.HumanoidRootPart.Position).Magnitude
				if mag <= TargetDistance and char.Humanoid.Health > 0 then
					TargetDistance = mag
					Target = char
				end
			end
		end
	else
		for i, char in pairs(workspace:GetDescendants()) do
			if char:IsA('Model') then
				if char:FindFirstChildWhichIsA('Humanoid') and char:FindFirstChild('HumanoidRootPart') and char ~= Zombie then
					local mag = (Zombie.HumanoidRootPart.Position - char.HumanoidRootPart.Position).Magnitude
					if mag <= TargetDistance and char.Humanoid.Health > 0 then
						TargetDistance = mag
						Target = char
					end
				end
			end
		end
	end
	return Target
end

while true do
	local targetplr = FindTarget()
	if targetplr then
		path:ComputeAsync(Zombie.HumanoidRootPart.Position, targetplr.HumanoidRootPart.Position)
		waypoints = path:GetWaypoints()
		for i, waypoint in pairs(waypoints) do
			if targetplr:FindFirstChild('Head') then
				if TargetType == 2 then
					local Future = targetplr.HumanoidRootPart.CFrame + (targetplr.HumanoidRootPart.Velocity * Epitaph + Vector3.new(0, .1, 0))
					Zombie.PrimaryPart.CFrame = CFrame.lookAt(Zombie.PrimaryPart.CFrame.Position, Future.Position)
				end
			end
			if waypoints[i].Action == Enum.PathWaypointAction.Jump then
				Zombie.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
			end
			Zombie.Humanoid:MoveTo(waypoint.Position)
			Zombie.Humanoid.MoveToFinished:Wait()
		end
	else
		task.wait()
	end
end

ill try my best to understand it

i see that you dont have alot of stuff
( just in mind if on function there is something it will be just in there so you need to make a
local

1 Like

what do you mean

eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee

oh wait you forgot to put game:GetService(“players”):getplayerfromcharcter i think these cuz you just get just player but with the char then it say oh this a char plus i do not use alot of path finding or those rigs since im scrpiting about them if i was i could help really fast because i am a dev about a game that i am right now updating it i just make like gui and scrpits and with the scrpiting that i know i do not have alot devs so i just make missions and cframce stuff

nevermind i got it its just server lag i guess

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.