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
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
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: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).
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