Hello, I am trying to make a part able to collide with players but not able to collide with any other part.
I tried searching up for a solution but collision groups are very weird and kind of complex to use.
I tried making a collision group named “Players” that contained every part of every player’s character and made it not able to collide with another group named “PlayerBlock” that contained all the parts I want to make collidable with the player only, but that didn’t work, it only worked the other way, meaning it can only collide with other parts that are not a player.
CollisionGroups are a bit weird at first but you’ll get used to it.
you also can create CollisionGroups using a script by using the PhysicsService, as shown below:
local PhysicsService = game:GetService("PhysicsService")
--// Create Collision Groups
PhysicsService:RegisterCollisionGroup("Players")
PhysicsService:RegisterCollisionGroup("PlayerBlock")
--// Set what they can collide with
PhysicsService:CollisionGroupSetCollidable("Players", "PlayerBlock", true) --// Players can collide with PlayerBlock
PhysicsService:CollisionGroupSetCollidable("PlayerBlock", "Default", false) --// PlayerBlock cannot colldie with the Default group (the Default being all of your parts that you haven't set a custom collsion group to)
and to apply these CollisionGroups into parts, you can do the following:
Part.CollisionGroup = "Players"
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
for Index, Part in pairs(Character:GetDescendants()) do
if Part:IsA("BasePart") then
Part.CollisionGroup = "Players"
end
end
end)
end)