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.
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
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