Part moving very slowly when my game contains alot of parts

  1. What do you want to achieve? Keep it simple and clear!
    Trying to make npc chase player at a game that contains alot of parts

  2. What is the issue? Include screenshots / videos if possible!
    the npc moves very slowly

heres the clip:

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    already tried setting the network owner to nil, but the result is still the same

Please help!

What type of movement method for the npc’s are you using?

Sorry, I don’t understand what you meant by movement method, what is movement method?

are there any properties in the workspace that could change this?

I think they mean what are you doing to move them.
Like tweens, moveto, etc.

I used the MoveTo method using PathFindingService. The problem is my game contains a lot of parts and making the chaser movements slow, Is there any solution regarding this problem?

What if you use a tween for each waypoint? (And wait for the tween to end before starting the new one)

Used tween for each waypoint, but it didn’t seems to work, the NPC is just standing still at the spawn, Is there another way to fix this?

you should probably only use moveTo when the npc is very close to the player. And use path finding service when the npc is far away from the player, too far to just run straight toward the player. Another thing could be that you have way too many npcs tryikng to use path finding service at once. So either cut on the number of npcs or try and slow down or limit how many npcs are using path finding service at once.

big edit:
i just remembered frorm my time working with PathFinding Service that using MoveTo alot of times can cause this effect where the npcs pause for a moment before moving again. Its a weird bug that you cant fix but can work around. The easiest work around is to make the waypoint spacing alot bigger that way the npcs have a longer distance to travel before calling on moveTo again. A harder and more risky work around would be to ditch the moveTo function entirely and use a repeat loop along with runservice to manually replicate the moveTo function. however you don’t seem like an experienced programmer so id say you stay away from the hard way. It can cause memory leaks or just be very hard to get to work. Try increasing the way point spacing

Already tried increasing the waypoint spacing but the results are still the same, it moves smoothly but EXTREMELY SLOW, And heres the clip:

As i said earlier, it moves very slow when my game contains a lot of parts, and is there a properties that i could change to fix this, i think this is unfixable tho.

please help!

idk man you might have to use other tools to fix this

ok you need to give us a more detailed description of what is going on in your game. how many parts are unanchored, now many npcs, how often are they using path finding service, how are they using path fi ding service. this is your game, we know absolutely nothing. saying there are alot of parts is not enough for us to help.

with that high ping, it’s probably because you’re doing too much in what I’d assume is a Runservice function. Try maybe sharing your code so that we can actually see what’s happening.

the unanchored parts are only the npcs

3 npc’s.

i used pathfinding service really often (this might be the problem)

this is the code:

local nrstt

while wait() do
	if RTB.Value == false then

		nrstt = GetTorso(hroot.Position)

		if nrstt ~= nil and human.Health > 0 and game.Players:GetPlayerFromCharacter(nrstt.Parent):WaitForChild("Attackable").Value == true then -- if player detected	

			print("theres human")

			vars.Wandering.Value = false
			vars.Chasing.Value = true
			local function checkw(t)
				local ci = 3
				if ci > #t then
					ci = 3
				end
				if t[ci] == nil and ci < #t then
					repeat ci = ci + 1 wait() until t[ci] ~= nil
					return Vector3.new(1,0,0) + t[ci]
				else
					ci = 3
					return t[ci]
				end
			end

			path = pfs:FindPathAsync(hroot.Position, nrstt.Position)

			waypoint = path:GetWaypoints()

			if path and waypoint or checkw(waypoint) then

				if checkw(waypoint) ~= nil and checkw(waypoint).Action == Enum.PathWaypointAction.Walk then
					human:MoveTo( checkw(waypoint).Position )
					human.Jump = false
				end

				if checkw(waypoint) ~= nil and checkw(waypoint).Action == Enum.PathWaypointAction.Jump then
					connection = human.Changed:connect(function()
						human.Jump = true
					end)
					human:MoveTo( waypoint[4].Position )
				end

				if connection then
					connection:Disconnect()
				end

			else
				for i = 3, #waypoint do
					human:MoveTo( waypoint[i].Position )	
				end
			end
			path = nil
			waypoint = nil
		elseif nrstt == nil then
			vars.Wandering.Value = true
			vars.Chasing.Value = false
			CchaseName = nil
			path = nil
			waypoint = nil

			walkRandomly()
			vars.Wandering.Value = false
		end
	end
end

please help :slight_smile:

I’d first start off by changing the While loop because that’s probably the main source of lag right there, you could probably have this firing once the player is moving, so just get the localplayer hrp and check for movement.

What might also be an issue, just from a quick glance, is that you’re setting your path and waypoint to nil, when the humanoids probably haven’t reached their destination yet. I could be completely wrong but I’d just put a couple of prints within the code to see if everything that’s supposed to be happening is actually happening.

I’m not really too good with the natural Pathfinding of roblox, so I could be wrong and that’s how you’re normally supposed to do it.

Also, if this is being fired from the server, I’d check to see how much power is being used to run this script, you can see the consumption by pressing Ctrl + F7 while in playtesting to see.

yeah this while loop is running more than once every frame. Its almost running as fast as possible so youre crushing the server by trying to find thousands of paths each second. The roblox page has a great tutourial and sample code that probably works exactly as youd need it to. It checks to see if the npc has finished the current path before starting a new one. Its what i used when i first started on path finding service, it was a great help.

https://create.roblox.com/docs/mechanics/pathfinding