How can i make a player temporarily noncollideable with other players

I have tried using collectionservice, but didn’t work out very well. I need the player to not be collideable with other players till I tell it to make it collideable again.

	for _,v in pairs(Character:GetChildren()) do
		if v:IsA("BasePart") then
			if Bool then
				v.CollisionGroup = "p"
			else
				v.CollisionGroup = "Default"
			end
		end
	end
1 Like

Here’s the script.

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

local GroupName = "Players"
PhysicsService:RegisterCollisionGroup(GroupName)
PhysicsService:CollisionGroupSetCollidable(GroupName, GroupName, false)

local function ChangeGroup(part)
    if part:IsA("BasePart") then
        part.CollisionGroup = GroupName
    end
end

local function HandleCharacterAdded(character)
    for _, part in ipairs(character:GetDescendants()) do
        ChangeGroup(part)
    end
end

Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        HandleCharacterAdded(character)

        character.ChildAdded:Connect(function(object)
            ChangeGroup(object)
        end)
    end)
end)
1 Like

You need a server script first to register all players to the Collision Group

-- Server-script to register collission group and add all players

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

physicsService:RegisterCollisionGroup("Characters")
physicsService:CollisionGroupSetCollidable("Characters", "Characters", true)

local function onDescendantAdded(descendant)
	-- Set collision group for any part descendant
	if descendant:IsA("BasePart") then
		descendant.CollisionGroup = "Characters"
	end
end

local function onCharacterAdded(character)
	-- Process existing and new descendants for physics setup
	for _, descendant in pairs(character:GetDescendants()) do
		onDescendantAdded(descendant)
	end
	character.DescendantAdded:Connect(onDescendantAdded)
end

-- Function to turn collide true/false

local function canCollide(bool)
	physicsService:CollisionGroupSetCollidable("Characters", "Characters", bool)
end

Players.PlayerAdded:Connect(function(player)
	-- Detect when the player's character is added
	player.CharacterAdded:Connect(onCharacterAdded)
end)

Now you can use the canCollide function to enable/disable (Only works on server)

local function canCollide(bool)
	physicsService:CollisionGroupSetCollidable("Characters", "Characters", bool)
end
--Example
canCollide(false)