How to make npcs and players not collide

I’ve been trying to make my NPCs to stop colliding with the player’s characters in-game.

I’ve tried using physics service, but that didn’t work. Here is the code for the physics service script, please help, and thanks!

local PS = game:GetService("PhysicsService")
PS:CreateCollisionGroup("Player")
PS:CollisionGroupSetCollidable("Player","Player",false)
PS:CreateCollisionGroup("NPC")
PS:CollisionGroupSetCollidable("NPC","NPC",false)

PS:CollisionGroupSetCollidable("NPC","Player",false)

game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
	Character:WaitForChild("HumanoidRootPart")
	Character:WaitForChild("Head")
	Character:WaitForChild("Humanoid")
	for i,v in pairs(Character:GetChildren()) do
		if v:IsA("BasePart") then
			PS:SetPartCollisionGroup(v,"Player")
		end
	end
end)
end)
spawn(function()
for i = 1,math.huge do
for _, v in pairs(game.Workspace.NPCS:GetChildren()) do
if v and v:FindFirstChildOfClass("Humanoid") then
	for _,b in pairs(v:GetChildren()) do
		if b:IsA("Part") then
			PS:SetPartCollisionGroup(b,"NPC")
		end
		wait()
	end
end
wait()
end
wait(0.001)
end
end)
5 Likes

Try turning off cancollide in the npc locally on the client.

2 Likes

The can collide just loop sets itself back on

1 Like

I think he meant literally looping through the descendants of the NPC on a local-sided script and setting the CanCollide value to false.

1 Like

Still didn’t work, this is the script i used.

local npcs = game.Workspace.NPCS

for i,obj in pairs(npcs:GetDescendants()) do

if obj:IsA("BasePart") then

obj.CanCollide = false

end

end

edit: is local-sided*

1 Like

Wait the instance NPCS is a folder with all the npc models right? Because that would mean there are no base parts there, just models.

Quickly copied your script then modified it. Might have some errors.

local npcs = game.Workspace.NPCS

for i,obj in pairs(npcs:GetDescendants()) do

if obj:IsA("Model") then

obj.HumanoidRootPart.Cancollide = false

end

end
1 Like

Im using GetDescendants(), so it does reach the baseparts of the npcs. will try out your script tho, thanks.

2 Likes

Sorry, but it didn’t work. I also forgot to include that the npc is a R6 rig.

1 Like

Could you post a picture of the NPCs folder?

2 Likes

Screen Shot 2020-03-30 at 9.12.03 PM

1 Like

inside the npc

Screen Shot 2020-03-30 at 9.13.10 PM

1 Like

Wait i just realised the issue with my script I wrote “Cancollide” instead of "CanCollide.

1 Like

fixed the typo, still doesn’t work.

1 Like

Try giving each NPC unique names. I doubt it will help but it would make the script less confusing to think about

1 Like

Thanks? It didn’t help, but thanks anyway.

1 Like

Wait i’ll try to fish out a similar script i made earlier to do a similar thing.

2 Likes

you have to use a runservice.Stepped loop on the client in order to make it non collidable; otherwise, it will just set the property right back to true

1 Like

Didn’t work for me, here’s the script:

local npcs = game.Workspace.NPCS

game:GetService("RunService").Stepped:Connect(function()

for i,obj in pairs(npcs:GetDescendants()) do

if obj:IsA("BasePart") then

obj.HumanoidRootPart.CanCollide = false

end

end

end)
1 Like
local npcs = game.Workspace.NPCS


for i,obj in pairs(npcs:GetDescendants()) do

if obj:IsA("BasePart") then
game:GetService("RunService").Stepped:Connect(function()

obj.CanCollide = false

end)

end

end

if this doesn’t work, it’s not the scripts fault

3 Likes

it didn’t work, is there any problems that could have caused this?

1 Like