Tower defense Npc walk issue

1.Npc walk to waypoints 1,2 is not have problem but this problem will when Npc walk to waypoint 3

Issue Video : Action 2-17-2022 2-24-33 PM

Mob move code

	spawn(function()
		local success, errorm = pcall(function()
			for _, waypoints in ipairs(map.Waypoints:GetChildren()) do
				local endPoint = {
					Position = waypoints.CFrame.Position
				}
				local TargetCFrame = CFrame.lookAt(name.HumanoidRootPart.Position, waypoints.Position)
				name.HumanoidRootPart.BodyGyro.CFrame = TargetCFrame
				--local Speed = name:WaitForChild('SpeedValue')
				local tweenInfo = TweenInfo.new(MobData[typeas].Speed, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
				local tween = tweenService:Create(name.PrimaryPart, tweenInfo, endPoint)
				tween:Play()
				tween.Completed:Wait(0.1)
			end
			Bindremote:Fire(name.Humanoid.Health)
			script.Broke:Play()
			name:Destroy()
	end)
end)

–Mob Spawn code

	local MobExist = serverstorage.Enemies:FindFirstChild(name)
	if MobExist then
		for i=1, quantity do
			task.wait(0.5)
			local newmob = MobExist:Clone()

			newmob.HumanoidRootPart.CFrame = workspace.Map.Start.CFrame
			newmob.Parent = workspace.Enemies
			newmob.HumanoidRootPart:SetNetworkOwner(nil)
			
			local speed = newmob:WaitForChild("SpeedValue")
			if Type == "Slow" then
				speed.Value = 5
				newmob.Humanoid:LoadAnimation(newmob.Animations.Walk):Play()
				local Gui = serverstorage.Info:Clone()
				Gui.Parent = newmob.Head
				Gui.Enabled = false
				local percent = newmob.Humanoid.Health / newmob.Humanoid.MaxHealth
				Gui.GUI.HealthGUI.HealthNum.Text = newmob.Humanoid.Health .. "/".. newmob.Humanoid.MaxHealth
				Gui.GUI.HealthGUI.Healthbar.Size = UDim2.new(percent,0,percent,0)
				Gui.GUI.Info.TextLabel.Text = ""
				Gui.GUI.Info.TextLabel.TextColor3 = Color3.new(0,0,0)
				Gui.GUI.HealthGUI.Script.Disabled = false	
			elseif Type == "Speed" then
				newmob.Humanoid.Health = newmob.Humanoid.Health / 0.5
				speed.Value = 2.149
				newmob.Humanoid:LoadAnimation(newmob.Animations.Run):Play()
				local Gui = serverstorage.Info:Clone()
				Gui.Parent = newmob.Head
				Gui.Enabled = false
				local percent = newmob.Humanoid.Health / newmob.Humanoid.MaxHealth
				Gui.GUI.HealthGUI.HealthNum.Text = newmob.Humanoid.Health .. "/".. newmob.Humanoid.MaxHealth
				Gui.GUI.HealthGUI.Healthbar.Size = UDim2.new(percent,0,percent,0)
				Gui.GUI.Info.TextLabel.Text = "Runner"
				Gui.GUI.Info.TextLabel.TextColor3 = Color3.new(1,0,0)
				Gui.GUI.HealthGUI.Script.Disabled = false	
			end
			for i, object in ipairs(newmob:GetDescendants())do
				if object:IsA('BasePart') then				
					phy:SetPartCollisionGroup(object ,"Enemies")
				end	
			end
			local BodyGyro = Instance.new('BodyGyro')
			BodyGyro.Parent = newmob.HumanoidRootPart
			BodyGyro.D = 0
			BodyGyro.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
			BodyGyro.CFrame = newmob.HumanoidRootPart.CFrame

			newmob.Humanoid.Died:Connect(function()
				newmob:Destroy()
			end)
			coroutine.wrap(mob.Move)(newmob,Type,map)
		end
	end

Pls help me

2 Likes

Could there be an issue with the position of the waypoint?

Are they R6 or R15? Write animation script inside of the toolbox, there will be animation scripts, try that (make sure you write the r6/r15 to the search).

My problem is not Animation
I need help to fix problem in video when Npc is turn to left

I would first verify there is not an issue with the 3rd waypoints position. You are turning the mob to face the position in your code. If the position is at an odd angle to the mob root part this could be causing it to fall through the map. Do the mobs have humanoid parts? I would also be ignoring Y axis when turning the mob since that would have the root part tilt toward the position, that often times causes problems.

1 Like