So, I am making a bigfoot type horror game. Hes supposed to go after the player when in range, and stop when not in range. He freezes after he kills a player, or when in a cave he just runs into the wall. I have no idea what could be causing this.
local ztor = script.Parent.HumanoidRootPart
local zhum = script.Parent.Humanoid
local function FindTar()
local agro = 150
local vector3 = Vector3.new(150,150,150)
local magnitude = vector3.Magnitude
local target
for i, v in pairs(workspace:GetChildren()) do
local hum = v:FindFirstChild("Humanoid")
local tor = v:FindFirstChild("HumanoidRootPart")
if hum and tor and v ~= script.Parent then
if v:FindFirstChild("HumanoidRootPart"):FindFirstChild("Foot") then
else
if (ztor.Position - tor.Position).Magnitude < agro then
agro = (ztor.Position - tor.Position).Magnitude
target = tor
end
end
end
end
return target
end
while wait(0.25) do
local tor = FindTar()
if tor then
print("sense")
script.Parent.Humanoid.WalkSpeed = 35
local finish = tor
local dummy = script.Parent
local humaoid = dummy.Humanoid
local PathfindingService = game:GetService("PathfindingService")
while true do
print("Found")
local path = PathfindingService:CreatePath()
path:ComputeAsync(dummy.HumanoidRootPart.Position, tor.Position)
local waypoints = path:GetWaypoints()
for i = 1, 5 do
if i <= #waypoints then
if waypoints[i].Action == Enum.PathWaypointAction.Jump then
humaoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
humaoid:MoveTo(waypoints[i].Position)
humaoid.MoveToFinished:Wait()
local function setNetworkOwnerOfBasePart(basePart, networkOwner)
local success, errorReason = basePart:CanSetNetworkOwnership()
if success then
basePart:SetNetworkOwner(networkOwner)
else
error(errorReason)
end
end
local function setNetworkOwnerOfModel(model, networkOwner)
for _, descendant in pairs(model:GetDescendants()) do
if descendant:IsA("BasePart") then
setNetworkOwnerOfBasePart(descendant, networkOwner)
end
end
end
local function setNetworkOwner(instance, networkOwner)
if instance:IsA("Model") then
setNetworkOwnerOfModel(instance, networkOwner)
elseif instance:IsA("BasePart") then
setNetworkOwnerOfBasePart(instance, networkOwner)
else
warn(instance.Name .. "'s network ownership cannot be modified.")
end
end
setNetworkOwner(script.Parent)
end
end
end
else
script.Parent.Humanoid.WalkSpeed = 15
end
end
