Somethings wrong with it and its not working
help pls
something in the Start function is not working
Right now the enemies don’t move at all
sending a rbxl down below
local ServerScriptService = game:GetService("ServerScriptService")
local ServerStorage = game:GetService("ServerStorage")
local PathfindingService = game:GetService("PathfindingService")
local Players = game:GetService("Players")
local ComponentModule = require(ServerScriptService.Component)
local Component = ComponentModule:New()
function Component:Start()
self.Character = self.Instance
self.Root = self.Character.HumanoidRootPart
self.Humanoid = self.Character.Humanoid
self.Path = PathfindingService:CreatePath({
AgentCanJump = false,
})
-- ComputationLoop
task.spawn(function()
while self.Character:IsDescendantOf(game) and self.Character:FindFirstChild("Humanoid") do
local ClosestPlayer, ClosestPlayerDistance
for _,Player in pairs(Players:GetPlayers()) do
if Player.Character and Player.Character:FindFirstChild("HumanoidRootPart") then
if not ClosestPlayerDistance then
ClosestPlayer, ClosestPlayerDistance = Player, (Player.Character.HumanoidRootPart.Position - self.Root.Position).Magnitude
elseif ClosestPlayerDistance > (Player.Character.HumanoidRootPart.Position - self.Root.Position).Magnitude then
ClosestPlayer, ClosestPlayerDistance = Player, (Player.Character.HumanoidRootPart.Position - self.Root.Position).Magnitude
end
end
end
if ClosestPlayer then
if ClosestPlayerDistance > self.Character:GetAttribute("AgroDistance") then
self.Path:ComputeAsync(self.Root.Position, ClosestPlayer.Character.HumanoidRootPart.Position)
self.Waypoints = self.Path:GetWaypoints()
self.NextTicket = 1
else
self.NextTicket = 1
self.Waypoints = nil
end
else
self.NextTicket = 1
self.Waypoints = nil
end
task.wait(0.1)
end
end)
-- MovementLoop
task.spawn(function()
while self.Character:IsDescendantOf(game) and self.Character:FindFirstChild("Humanoid") do
if self.Waypoints and #self.Waypoints ~= 0 then
self.Humanoid:MoveTo(self.Waypoints[self.NextTicket]["Position"])
end
task.wait(0.1)
end
end)
-- MoveOnFinished
--self.Humanoid.MoveToFinished:Connect(function()
-- if self.Waypoints then
-- self.NextWaypoint += 1
-- if self.Waypoints[self.NextWaypoint] then
-- self.Humanoid:MoveTo(self.Waypoints[self.NextWaypoint]["Position"])
-- end
-- end
--end)
self.Humanoid.Died:Connect(function()
self.Humanoid.Health = 100
self.Character:Clone().Parent = workspace
self.Character:Destroy()
end)
end
function Component:Stop()
-- Nothing to clean but function is required :)
end
Component:BindToTag("Zombie")
return Component