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:CreateCollisionGroup("Player") ps:CreateCollisionGroup("Platform") ps:CollisionGroupSetCollidable("Player", "Platform", false) plat = game.Workspace.Platform1 plat.Touched:Connect(function(hit) h = hit.parent:FindFirstChild("Humanoid") if h then ps:SetPartCollisionGroup("Player" ,h) wait(plat.TouchEnded) ps:RemoveCollisionGroup(h, "Player") end end)
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 ps:SetPartCollisionGroup(part,"Player") end end
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.