Coliding with humanoid

Hi devs,
im making it so an npc occasionally disappears. inorder to achieve this, i set all the parts of the npcs cancollide off, however, when i set the humanoidrootparts cancollide to off and then anchor it, it puts cancollide on automatically in game. This gives the players a chance to hit it. Does anybody know any solutions

script.Parent.HumanoidRootPart.CanCollide = true
			script.Parent.HumanoidRootPart.Anchored = false
1 Like

Humanoid root part’s cancolide property is set to true in loop by studio automaticaly, because it is root part specified in humanoids object, the only thing that might work is teleporting it off the map, or adding if statement while executing hit code

3 Likes

You got two options. Make a collision group for the humanoid, or keep setting the CanCollide property off in either a while loop or a runservice loop.

5 Likes

when i try set all the parts in the player to the collision group with a loop that goes through all the players, it tries to set the humanoid to the group which breaks it

local PhysicsService = game:GetService(“PhysicsService”)

local root = “root”

local plr = “plr”
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
– Register two collision groups

PhysicsService:RegisterCollisionGroup(root)

PhysicsService:RegisterCollisionGroup(plr)

workspace.Ghost.Noobnoobie87.HumanoidRootPart.CollisionGroup = root
local children = player.Character:GetChildren()
for i = 1, #children do

		children[i].CollisionGroup = plr

end


PhysicsService:CollisionGroupSetCollidable(root, plr, false)
end)
end)

‘’’

1 Like

That’s because you are performing any checks to make sure that the Instance is a BasePart and the result is the code trying to apply the property on an Instance that does not inherit it.
All BaseParts Inherit the CollisionGroup Property, so It would be safe to validate that it is a BasePart using :IsA()

2 Likes

local children = player.Character:GetChildren()

	for i = 1, #children do
		if children[i]:IsA("BasePart") then
		children[i].CollisionGroup = plr
	end
end

tried this but doesnt work

1 Like

try using RunService to disable collisions (this has worked for me.)

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

script.Parent.HumanoidRootPart.CanCollide = false
script.Parent.HumanoidRootPart.Anchored = false

end)

Not to be nosy, but try refraining from using deprecated methods. They can cause bugs.

--you can still set collision groups with PhysicsService, but to set parts:
Part.CollisionGroup = "GroupName"
1 Like