How to make NPCs not collide with each other

I have a script that spawns NPCs at random and have them walk along a path. My problem is I want them to walk through each other but I can’t seem to find a solution to disable collision for them. This is the code that deals with all the NPCs

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Folder1 = game.Workspace.PathFindingGlobal.Side2.MoveAcrossSidewalk1
local Folder2 = game.Workspace.PathFindingGlobal.Side2.MoveAcrossSidewalk2
local fjdks = true
local model = ReplicatedStorage.Rig
local humanoid = model.Humanoid


local function pp()
	local randPos = math.random(1,2)

	local newModel = model:Clone()
	local newModelHumanoid = newModel.Humanoid
	newModel.Parent = game.Workspace.NPCS
	if randPos == 1 then
		newModel:PivotTo(CFrame.new(Folder1:FindFirstChild('1').CFrame.Position))
		for i, v in pairs(Folder1:GetChildren()) do
			newModelHumanoid:MoveTo(Folder1:FindFirstChild(i).Position)
			newModelHumanoid.MoveToFinished:Wait()	
		end
	else
		newModel:PivotTo(CFrame.new(Folder1:FindFirstChild('9').CFrame.Position))
		for i, v in pairs(Folder2:GetChildren()) do
			newModelHumanoid:MoveTo(Folder2:FindFirstChild(i).Position)
			newModelHumanoid.MoveToFinished:Wait()	
		end
	end

	newModel:Destroy()
end

while true do
	coroutine.wrap(pp)()
	task.wait(math.random(2,5)) 
end

Change Collision Groups, read more here: Collisions | Documentation - Roblox Creator Hub
if u still have questions lmk

3 Likes

Here is what I got so far although it doesn’t seem to work.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Folder1 = game.Workspace.PathFindingGlobal.Side1.MoveAcrossSidewalk1
local Folder2 = game.Workspace.PathFindingGlobal.Side1.MoveAcrossSidewalk2
local fjdks = true
local model = ReplicatedStorage.Rig
local humanoid = model.Humanoid
local PhysicsService = game:GetService("PhysicsService")
local NPCS = game.Workspace.NPCS:GetChildren()



local function pp()
	local randPos = math.random(1,2)

	local newModel = model:Clone()
	local newModelHumanoid = newModel.Humanoid
	newModel.Parent = game.Workspace.NPCS
	
	local npcGroup = "NPCS"
	PhysicsService:RegisterCollisionGroup(npcGroup)
	PhysicsService:CollisionGroupSetCollidable(npcGroup,npcGroup, false)

	NPCS.CollisionGroup = npcGroup
	
	if randPos == 1 then
		newModel:PivotTo(CFrame.new(Folder1:FindFirstChild('1').CFrame.Position))
		for i, v in pairs(Folder1:GetChildren()) do
			newModelHumanoid:MoveTo(Folder1:FindFirstChild(i).Position)
			newModelHumanoid.MoveToFinished:Wait()	
		end
	else
		newModel:PivotTo(CFrame.new(Folder1:FindFirstChild('9').CFrame.Position))
		for i, v in pairs(Folder2:GetChildren()) do
			newModelHumanoid:MoveTo(Folder2:FindFirstChild(i).Position)
			newModelHumanoid.MoveToFinished:Wait()	
		end
	end

	newModel:Destroy()
end

while true do
	coroutine.wrap(pp)()
	task.wait(math.random(2,5)) -- the time between each npc
end

Try this:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Folder1 = game.Workspace.PathFindingGlobal.Side1.MoveAcrossSidewalk1
local Folder2 = game.Workspace.PathFindingGlobal.Side1.MoveAcrossSidewalk2
local fjdks = true
local model = ReplicatedStorage.Rig
local humanoid = model.Humanoid
local PhysicsService = game:GetService("PhysicsService")
local NPCS = game.Workspace.NPCS:GetChildren()



local function pp()
	local randPos = math.random(1,2)

	local newModel = model:Clone()
	local newModelHumanoid = newModel.Humanoid
	newModel.Parent = game.Workspace.NPCS

	local npcGroup = "NPCS"
	PhysicsService:RegisterCollisionGroup(npcGroup)
	PhysicsService:CollisionGroupSetCollidable(npcGroup,npcGroup, false)

	newModel.CollisionGroup = npcGroup

	if randPos == 1 then
		newModel:PivotTo(CFrame.new(Folder1:FindFirstChild('1').CFrame.Position))
		for i, v in pairs(Folder1:GetChildren()) do
			newModelHumanoid:MoveTo(Folder1:FindFirstChild(i).Position)
			newModelHumanoid.MoveToFinished:Wait()	
		end
	else
		newModel:PivotTo(CFrame.new(Folder1:FindFirstChild('9').CFrame.Position))
		for i, v in pairs(Folder2:GetChildren()) do
			newModelHumanoid:MoveTo(Folder2:FindFirstChild(i).Position)
			newModelHumanoid.MoveToFinished:Wait()	
		end
	end

	newModel:Destroy()
end

while true do
	coroutine.wrap(pp)()
	task.wait(math.random(2,5)) -- the time between each npc
end

ServerScriptService.NpcWalkingSidewalk:38: Parameter 1 must be BasePart in SetPartCollisionGroup.

Test one more time, i updated.

It is still showing this:

ServerScriptService.NpcWalkingSidewalk:43: CollisionGroup is not a valid member of Model “Workspace.NPCS.Rig”

I think running a for loop to find all the baseparts in newModel and then setting those to the collision group might work (newModel is only a model itself).

1 Like

I’m going to try that and let you know if it works.

Yes, that will work.

dontmindthistext

Okay I got it to work this is the code if you are interested:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Folder1 = game.Workspace.PathFindingGlobal.Side1.MoveAcrossSidewalk1
local Folder2 = game.Workspace.PathFindingGlobal.Side1.MoveAcrossSidewalk2
local fjdks = true
local model = ReplicatedStorage.Rig
local humanoid = model.Humanoid
local PhysicsService = game:GetService("PhysicsService")
local NPCS = game.Workspace.NPCS



local function pp()
	local randPos = math.random(1,2)

	local newModel = model:Clone()
	local newModelHumanoid = newModel.Humanoid
	newModel.Parent = game.Workspace.NPCS

	local npcGroup = "NPCS"
	PhysicsService:RegisterCollisionGroup(npcGroup)
	PhysicsService:CollisionGroupSetCollidable(npcGroup,npcGroup, false)
	
	for i, v in pairs(NPCS:GetDescendants()) do
		if v:IsA'BasePart' then
			v.CollisionGroup = npcGroup
		end
	end
	

	if randPos == 1 then
		newModel:PivotTo(CFrame.new(Folder1:FindFirstChild('1').CFrame.Position))
		for i, v in pairs(Folder1:GetChildren()) do
			newModelHumanoid:MoveTo(Folder1:FindFirstChild(i).Position)
			newModelHumanoid.MoveToFinished:Wait()	
		end
	else
		newModel:PivotTo(CFrame.new(Folder1:FindFirstChild('9').CFrame.Position))
		for i, v in pairs(Folder2:GetChildren()) do
			newModelHumanoid:MoveTo(Folder2:FindFirstChild(i).Position)
			newModelHumanoid.MoveToFinished:Wait()	
		end
	end

	newModel:Destroy()
end

while true do
	coroutine.wrap(pp)()
	task.wait(math.random(2,5)) -- the time between each npc
end

Thanks for the help!

No problem, glad I helped you.