Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Is there a way to make players go through npcs?

I want my players to be able to go through NPCs as if i simply turned off cancollide. i have tried using collision groups like this:

local phyicsService = game:GetService('PhysicsService')

local plr, npc = 'Player', 'NPC'

local setPlr = phyicsService:CreateCollisionGroup(plr)
local setNpc = phyicsService:CreateCollisionGroup(npc)

phyicsService:CollisionGroupSetCollidable(plr, npc, false)

function addToCollisionGroup(mod, group)
	for k, v in pairs(mod:GetChildren()) do
		if v:IsA('BasePart') then
			phyicsService:SetPartCollisionGroup(v, group)
		end
	end
end

addToCollisionGroup(workspace.NPC, npc)
addToCollisionGroup(workspace.NPC2, npc)
addToCollisionGroup(workspace.NPC3, npc)

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		addToCollisionGroup(char, plr)
	end)
end)

I have tried many tings like that, but this is the closest ive gotten. it didnt work. any thoughts?

1 answer

You can use i,v in pairs() to do it. You can use GetDescendants to find which is a part or not, and then add a simple if statement

for i,v in pairs(game.Workspace.Npc:GetDescendants()) do -- basic for i,v in pairs

Now we need to determine which is a part or not, so like I said we can use an if statement

for i,v in pairs(game.Workspace.Npc:GetDescendants()) do
if v:IsA("Part") then -- find the parts of the npc

Now that we have all the parts in the npc, we can make it to where CanCollide = false

for i,v in pairs(game.Workspace.Npc:GetDescendants()) do
if v:IsA("Part") then -- find the parts of the npc
v.CanCollide = false
end
end

3 comments

0

um that didnt work

0

You have to replace game.Workspace.NPC with the name of your npc

0

i know

This discussion is preserved as it was. New answers, comments, and votes are closed.