I want to make the zombie go to the player and at 50 it will just stop.
However,My zombie just teleports.
local PathfindingService = game:GetService("PathfindingService")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local humanoid = script.Parent:WaitForChild("Humanoid")
local Torso = script.Parent:WaitForChild("HumanoidRootPart")
local zombie = script.Parent
local Range = 500
local shootDis = 50
RunService.Heartbeat:Connect(function(dl)
for i, player in pairs(Players:GetPlayers()) do
local distance = (player.Character.PrimaryPart.Position - Torso.Position).Magnitude
if distance < Range then
local Path = PathfindingService:CreatePath(
{AgentRadius = 2,
AgentHeight = 5,
AgentCanJump = true,
AgentCanClimb = true,
WaypointSpacing = 4})
Path:ComputeAsync(Torso.Position, player.Character.PrimaryPart.Position)
local Waypoints = Path:GetWaypoints()
if Path.Status == Enum.PathStatus.Success then
for i, waypoint in pairs(Waypoints) do
humanoid:MoveTo(waypoint.Position)
end
end
if distance < shootDis then
humanoid:ChangeState(Enum.HumanoidStateType.PlatformStanding)
Torso.Anchored = true
wait(1)
Torso.Anchored = false
humanoid:ChangeState(Enum.HumanoidStateType.Running)
end
end
end
end)