Hello! I am attempting to disable collision on npcs however I encountered a quite difficult challenge, you see, my npcs are made via cloning so the script that I am using in serverscriptservice
local brickmin = workspace.Brickmin
local ps = game:GetService("PhysicsService")
ps:CreateCollisionGroup("PlayersGroup")
ps:CreateCollisionGroup("NpcsGroup")
ps:CollisionGroupSetCollidable("PlayersGroup", "NpcsGroup", false)
for _,npc in pairs(brickmin:GetChildren()) do
for _,v in pairs(npc:GetDescendants()) do
if v:IsA("BasePart") then
ps:SetPartCollisionGroup(v,"NpcsGroup")
end
end
end
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
wait()
for _,v in pairs(char:GetChildren()) do
if v:IsA("BasePart") then
ps:SetPartCollisionGroup(v,"PlayersGroup")
end
end
end)
end)
doesn’t actually do anything since when the game is ran the brickmin folder is empty since no clones have been created, I just wanted to know if it was possible to maybe run this script when a clone is created or if there’s an alternative method I could use.
local function OnNPCAdded(npc)
for _,v in pairs(npc:GetDescendants()) do
if v:IsA("BasePart") then
ps:SetPartCollisionGroup(v,"NpcsGroup")
end
end
end
for _,npc in pairs(brickmin:GetChildren()) do
OnNPCAdded(npc)
end
brickmin.ChildAdded:Connect(OnNPCAdded)
You’re right, I have changed the script to fit that.
local brickmin = workspace.Brickmin
local ps = game:GetService("PhysicsService")
ps:RegisterCollisionGroup("PlayersGroup")
ps:RegisterCollisionGroup("NpcsGroup")
ps:CollisionGroupSetCollidable("PlayersGroup", "NpcsGroup", false)
local function OnNPCAdded(npc)
for _,v in pairs(npc:GetDescendants()) do
if v:IsA("BasePart") then
ps:SetPartCollisionGroup(v,"NpcsGroup")
end
end
end
for _,npc in pairs(brickmin:GetChildren()) do
OnNPCAdded(npc)
end
brickmin.ChildAdded:Connect(OnNPCAdded)
brickmin.ChildAdded:Connect(function(npc)
for _,v in pairs(npc:GetDescendants()) do
if v:IsA("BasePart") then
ps:SetPartCollisionGroup(v,"NpcsGroup")
end
end
end)
Btw, SetPartCollissionGroup is deprecated and doesn’t work, instead do this:
ps.CollisionGroup = "NpcsGroup"
Updated Code:
local brickmin = workspace.Brickmin
local ps = game:GetService("PhysicsService")
ps:RegisterCollisionGroup("PlayersGroup")
ps:RegisterCollisionGroup("NpcsGroup")
ps:CollisionGroupSetCollidable("PlayersGroup", "NpcsGroup", false)
local function OnNPCAdded(npc)
for _,v in pairs(npc:GetDescendants()) do
if v:IsA("BasePart") then
ps.CollisionGroup = "NpcsGroup"
end
end
end
for _,npc in pairs(brickmin:GetChildren()) do
OnNPCAdded(npc)
end
brickmin.ChildAdded:Connect(OnNPCAdded)
brickmin.ChildAdded:Connect(function(npc)
for _,v in pairs(npc:GetDescendants()) do
if v:IsA("BasePart") then
ps.CollisionGroup = "PlayersGroup"
end
end
end)
local brickmin = workspace.Brickmin
local ps = game:GetService("PhysicsService")
ps:RegisterCollisionGroup("PlayersGroup")
ps:RegisterCollisionGroup("NpcsGroup")
ps:CollisionGroupSetCollidable("PlayersGroup", "NpcsGroup", false)
local function OnNPCAdded(npc)
for _,v in pairs(npc:GetDescendants()) do
if v:IsA("BasePart") then
v.CollisionGroup = "NpcsGroup"
end
end
end
for _,npc in pairs(brickmin:GetChildren()) do
OnNPCAdded(npc)
end
brickmin.ChildAdded:Connect(OnNPCAdded)
brickmin.ChildAdded:Connect(function(npc)
for _,v in pairs(npc:GetDescendants()) do
if v:IsA("BasePart") then
v.CollisionGroup = "PlayersGroup"
end
end
end)