How to disable collisions on players

Hey! I’m K0rrupt!

I know the question that I’m about to ask may seem a little weird but:
How do we enable collisions for players so that you can just go through the player?

7 Likes

You can activate collisions by putting this script in ServerScriptService.

https://www.roblox.com/library/2176459411/Disable-Player-Collisions-Script

3 Likes

You would need to use Collision Groups and Physics Service
Variables:

local PhysicsService = game:GetService("PhysicsService")
local PlayerService = game:GetService("Players")

Either create a collision group prior to using this script or do this:

PhysicsService:CreateCollisionGroup("PlayerCharacters")

Set the Player collision group to be not collide-able with other players (this can be done manually as well):

CollisionGroupSetCollidable("PlayerCharacters", "PlayerCharacters", false)

If you would do the set-up manually then it should look something like this:
image

Then on player and character added do the following:

local function characterAdded(character)

end

local function playerAdded(player)
   player.CharacterAdded:Connect(characterAdded)
end

PlayerService.PlayerAdded:Connect(playerAdded)

Now run through the bodyparts of the character like so:

for _, bodyPart in pairs(character:GetChildren()) do
   if bodyPart:IsA("BasePart") then
      PhysicsService:SetPartCollisionGroup(bodyPart, "PlayerCharacters")
   end
end

Though sometimes the script might have some delay so we want to go through the already joined players:

for _, player in pairs(PlayerService:GetPlayers()) do
   playerAdded(player)
end

Same for the characters of the players

if player.Character then
   characterAdded(player.Character)
end

The full script would look something like this:

-- Variables
local PhysicsService = game:GetService("PhysicsService")
local PlayerService = game:GetService("Players")

-- Collision group set-up
PhysicsService:CreateCollisionGroup("PlayerCharacters")
CollisionGroupSetCollidable("PlayerCharacters", "PlayerCharacters", false)

-- Functions & connections
local function characterAdded(character)
   for _, bodyPart in pairs(character:GetChildren()) do
      if bodyPart:IsA("BasePart") then
         PhysicsService:SetPartCollisionGroup(bodyPart, "PlayerCharacters")
      end
   end
end

local function playerAdded(player)
   player.CharacterAdded:Connect(characterAdded)

   if player.Character then
      characterAdded(player.Character)
   end
end

for _, player in pairs(PlayerService:GetPlayers()) do
   playerAdded(player)
end

PlayerService.PlayerAdded:Connect(playerAdded)
24 Likes

Roblox actually has a Developer article on disabling Player to Player Collisions! The method is quite similar to what @KJry_s has posted above. You can still read through the article, it has some great information, explanations, as well as additional methods!

Here is a link to the article: https://developer.roblox.com/en-us/articles/Player-Player-Collisions

Here is the script sourced from the Developer API Article Above:

local PhysicsService = game:GetService("PhysicsService")
local Players = game:GetService("Players")

local playerCollisionGroupName = "Players"
PhysicsService:CreateCollisionGroup(playerCollisionGroupName)
PhysicsService:CollisionGroupSetCollidable(playerCollisionGroupName, playerCollisionGroupName, false)

local previousCollisionGroups = {}

local function setCollisionGroup(object)
	if object:IsA("BasePart") then
		previousCollisionGroups[object] = object.CollisionGroupId
		PhysicsService:SetPartCollisionGroup(object, playerCollisionGroupName)
	end
end

local function setCollisionGroupRecursive(object)
	setCollisionGroup(object)

	for _, child in ipairs(object:GetChildren()) do
		setCollisionGroupRecursive(child)
	end
end

local function resetCollisionGroup(object)
	local previousCollisionGroupId = previousCollisionGroups[object]
	if not previousCollisionGroupId then return end 

	local previousCollisionGroupName = PhysicsService:GetCollisionGroupName(previousCollisionGroupId)
	if not previousCollisionGroupName then return end

	PhysicsService:SetPartCollisionGroup(object, previousCollisionGroupName)
	previousCollisionGroups[object] = nil
end

local function onCharacterAdded(character)
	setCollisionGroupRecursive(character)

	character.DescendantAdded:Connect(setCollisionGroup)
	character.DescendantRemoving:Connect(resetCollisionGroup)
end

local function onPlayerAdded(player)
	player.CharacterAdded:Connect(onCharacterAdded)
end

Players.PlayerAdded:Connect(onPlayerAdded)
17 Likes

a little late to this topic but incase anyone else comes along i’d like to point out that roblox has released a post about changes to collision groups, which will break this script eventually. by replacing some things you could probably fix it easily, but i’m too lazy to come up with a remade script myself right now.

the post can be found here

1 Like

Thanks!

You can’t disable collisions between the player and other players, however you can disable collisions between the player and the terrain.
local player = game.Players.LocalPlayer
local humanoid = player.Character.Humanoid

humanoid.WalkSpeed = 100
humanoid.PlatformStand = true
humanoid.JumpPower = 0

1 Like

I needed this today so here’s an update, in as minimal form as I could find (inspired by Disable Player Collisions | 2 Minute Scripting :scroll: - YouTube).

local PhysicsService = game:GetService("PhysicsService")
PhysicsService:RegisterCollisionGroup("Participants")
PhysicsService:CollisionGroupSetCollidable("Participants", "Participants", false)

local function disableCollisions(character)
    for _, bodyPart in pairs(character:GetChildren()) do
        if bodyPart:IsA("BasePart") then
            bodyPart.CollisionGroup = "Participants"
        end
    end
end

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(disableCollisions)
end)

You don’t need to do this at start up, if for some reason your bloxers need to get cozy temporarily. Just assign the CollisionGroup back to “Default” to restore:

local function enableCollisions(character: Model)
    for _, bodyPart: BasePart in pairs(character:GetChildren()) do
        if bodyPart:IsA("BasePart") then
            bodyPart.CollisionGroup = "Default"
        end
    end
end

Please be sure to run it in a Server script, it won’t work in a local script, as the docs explain:

Creating, deleting, and modifying collision relationships between collision groups is limited to server-side Scripts.

10 Likes