Are non-player limbs CanCollide forced?

Hi! I’m not sure if this belongs in this section, however I anticipate a response being somewhat code related for my issue given it’s nature
My issue here is that I anticipated NPC Humanoid characters to have nonsolid arms and legs like Roblox Player characters, however this is not the case and I’m not sure why. Because of this, my punch animations played on an NPC causes the player being punched to be shoved and pushed back due to hitting the arms that are supposed to clip through the player. I’ve tried looping through the limbs to make them CanCollide false, however it seems that the limbs are set to be solid instantly once the game has started and when the game is running. Is there any way around this or do I have to create a loop as well to bypass this in some way?

The issues are shown in further detail below:

And this is the behavior I would like from my NPC, for the arms to be non solid:

1 Like

Perhaps look into PhysicsService, and its collision groups.

You could add all of the limbs to a collision group which does not collide with the players.

3 Likes

Thank you for the links and help! I had no idea something like that existed! However, why does this happen in the first place with the limbs? I’m pretty confused why the behavior is different from player to nonplayer and I would like to avoid this issue in the future by knowing the cause

1 Like

Humanoid spaghetti code.

How does your NPC’s RigType look like?

Then there’s also the State types idk.

2 Likes

Yes it seems pretty odd. I think I was having the same problem with changing an NPC’s walkspeed at one point it time but it was fixed by changing it in script. But you said you did that with CanCollide so I’m not sure…

2 Likes

My rigtype is the standard R6 setup you get from importing an R6 dummy into the workspace from Roblox’s plugin, heres an image:


For extra clarification as well, the scripts inside do not effect the arms being solid whatsoever, I’ve tested with and without the scripts running and the end result is the same with the weird effect of the arms being solid.

And oh, I guess there wouldn’t much getting around that then. So my best bet would be excluding the collisions manually through PhysicsService? If not, I would hate to have to implement some weird workaround that loops the CanCollide property on both arms faster than what it’s at right now, that would be an optimization nightmare and not work for larger amounts of NPCs at all…
Thanks for all the help though, I’ll see what I can do in the morning!

Alright, I was able to fix the issue! I used Collision Filtering to put players body parts in a group as well as the NPC’s arms and set them to not collide with each other. Here’s the results now so far:


No more getting knocked around when punched by the NPC woooo!

I’m also including some messy temporary fix code I wrote to try and help anyone that has this issue as well in the future, definitely modify it to fit your needs or touch it up if you like:

local Players = game:GetService("Players")
local NPC = script.Parent
local PhysicsService = game:GetService("PhysicsService")

local playerChars = "playerChars"
local npcArms = "npcArms"

PhysicsService:CreateCollisionGroup(playerChars)
PhysicsService:CreateCollisionGroup(npcArms)

PhysicsService:SetPartCollisionGroup(NPC:FindFirstChild("Right Arm"), npcArms)
PhysicsService:SetPartCollisionGroup(NPC:FindFirstChild("Left Arm"), npcArms)

local function armFix(targetPlr)
	for i,v in pairs(targetPlr:GetChildren()) do
		if v:IsA("BasePart") then
			PhysicsService:SetPartCollisionGroup(v, playerChars)
		end
	end
end

local function onCharacterAdded(character)
	armFix(character)
	character.ChildAdded:Connect(armFix)
end
local function onPlayerAdded(player)
	player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)

PhysicsService:CollisionGroupSetCollidable(playerChars, npcArms, false)

Paste the code in a script parented to your NPCs, and it should work properly! Again, if you plan to use this in any way for larger scale situations you should definitely modify it to be less of a mess and try using the collection service so you’re not stuck messing with every instance of this script in NPCs when you want to make modifications!

2 Likes