The zombie pause to move when the animation’s play, how to make the zombie keep moving when the animation play? and is there any way to make the loop a little bit lighter, because im using while loop for server side
local PathfindingService = game:GetService("PathfindingService")
local zombie = workspace:WaitForChild("Dummy")
local humanoid = zombie:WaitForChild("Humanoid")
local nearest
local path = PathfindingService:CreatePath()
local d = false
local het = false
local pley = humanoid:LoadAnimation(script.Attack)
local function hitting(hit)
if hit.Parent.Name ~= zombie.Name and hit.Parent:FindFirstChild("Humanoid") and het == false then
het = true
hit.Parent.Humanoid:TakeDamage(10)
end
end
while wait() do
local player = game.Players:GetPlayers()
for i,v in pairs(player) do
local chars = v.Character or v.CharacterAdded:Wait()
if (chars.HumanoidRootPart.Position - zombie.HumanoidRootPart.Position).Magnitude <= 100 then
nearest = chars.HumanoidRootPart
end
end
path:ComputeAsync(zombie.HumanoidRootPart.Position,nearest.Position)
local waysPoint = path:GetWaypoints()
if #waysPoint >= 2 then
for i,v in pairs(waysPoint) do
humanoid:MoveTo(v.Position)
end
end
if (nearest.Position - zombie.HumanoidRootPart.Position).Magnitude <= 5 and d == false then
d = true
pley:Play()
if pley.IsPlaying then
if (nearest.Position - zombie.HumanoidRootPart.Position).Magnitude > 5 then
pley:Stop()
else
zombie.RightHand.Touched:Connect(hitting)
zombie.LeftHand.Touched:Connect(hitting)
end
end
pley.Stopped:Wait()
d = false
het = false
end
end