New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
Log in to vote

How could I add a players character to a collision group?

Asked by
kolenk 9
4 months ago

I'm trying to make a platform that you can jump through and stand on and I'm trying to use collision groups. I'm not very familiar with them and this is my first time trying them, but could anyone tell me how I would go about adding a player's character to a collision group? When I tried it, it said only BaseParts could be in collision groups? My code is below

local ps = game:GetService("PhysicsService")

ps:CollisionGroupSetCollidable("Player", "Platform", false)

plat = game.Workspace.Platform1

    h = hit.parent:FindFirstChild("Humanoid")
    if h then
ps:SetPartCollisionGroup("Player" ,h)
ps:RemoveCollisionGroup(h, "Player")

1 answer

Log in to vote
Answered by 4 months ago
Edited 4 months ago

Two things aren't correct. The first is that the error message is correct, you can't set the collision group of the Humanoid instance, you have to do it for each part in the character model. The second is that you have the arguments to SetPartCollisionGroup in reverse order, the part is the first argument and the name of the collision group is the second.

To set all the parts in a player model to the collision group "Player", you'd do this:

local function SetCharacterCollisionGroup(char) -- char is a player.Character model
for _,part in pairs(char:GetDescendants()) do
    if part:IsA("BasePart") then

Technically, I think you only need to set the collision group on parts that are CanCollide true, which are normally just the HumanoidRootPart, UpperTorso, LowerTorso, and Head for R15. But it's safest to set it on everything, otherwise if you have some accessory, tool, or anything else added to the character during the game, it could make them not able to pass through if it has any collidable parts inside. Roblox catalog accessories normally don't, but if it's a user-made asset, all bets are off.

I also think for wait(plat.TouchEnded) what you want is plat.TouchEnded:Wait()

Lastly, I'd be kind of surprised if setting the collision group on Touched like this actually works. I would not expect it to react quickly enough, and for the character to glitch. My instinct would be to set the collision group well in advance of the character actually coming into contact with the platform.


Answer this question