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:
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)