Pathfinding Not Working Properly

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make it so when a dummy collides with a part which has a health value the health of the part will reduce from as much as the dummy’s health is
  2. What is the issue? Include screenshots / videos if possible!
    I’m using pathfinding . Whenever the dummy hits the part it goes back to the waypoints I used to pathfind instead of reducing the health.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried some stuffs but they didn’t work . I did look for solutions .
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
-- This is an example Lua code block
```wait(10)
(this the is the main code)
local spawnTime = 5 -- spawn time in seconds
local spawnRate = 1 -- per spawn time

local physics = game:GetService("PhysicsService")
physics:CreateCollisionGroup("Mobs")
physics:CollisionGroupSetCollidable("Mobs", "Mobs", false)


while script.Parent.Building.Health.Value > 0 do
	wait()
	
	for i = 1, spawnRate do
		wait(spawnTime)


		local dummy = game:GetService("ReplicatedStorage").Mobs:GetChildren()[math.random(1, #game:GetService("ReplicatedStorage").Mobs:GetChildren())]:Clone()
		dummy.Parent = script.Parent.Mobs
		for i, v in pairs(dummy:GetChildren()) do
			if v:IsA("MeshPart") or v:IsA("Part") then
				physics:SetPartCollisionGroup(v, "Mobs")
			end
		end
		dummy.Humanoid.WalkSpeed = math.random(6,25)
		dummy.HumanoidRootPart.CFrame = script.Parent.Map.Spawns.Spawn.CFrame
		
		local pFS = game:GetService("PathfindingService")
		
		
		spawn(function()
			for _, waypoints in pairs(script.Parent.Waypoints:GetChildren()) do
				local path = pFS:CreatePath()
				path:ComputeAsync(dummy.HumanoidRootPart.Position, waypoints.Position)
				local wp = path:GetWaypoints()
				for __, wp2 in pairs (wp) do
					dummy.Humanoid:MoveTo(wp2.Position)
					dummy.Humanoid.MoveToFinished:Wait()
					
				end
			end
			script.Parent.Building.Health.Value = script.Parent.Building.Health.Value - math.random(1,10)
		end)
		
	end
	
end
(Part's code)
local health = script.Parent.Health

local healthFront = script.Parent.HealthGui.Background.Front

local healthText = script.Parent.HealthGui.Background.HealthText

function change()

local tween = game:GetService("TweenService"):Create(healthFront, TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false , 0), {Size = UDim2.new(health.Value / script.Parent.MaxHealth.Value, 0, 1, 0)})

tween:Play()

healthText.Text = "Health: "..tostring(health.Value).." / "..tostring(script.Parent.MaxHealth.Value)

end

change()

health.Changed:Connect(function()

change()

end)



Please do not ask people to write entire scripts or design entire systems for you. If you can't answer the three questions above, you should probably pick a different category.