Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

A Problem with Player-Player Collisions?

I'm trying to code a Player-Player Collisions system. But Player and Player are still be able to collide each other Note: Im in Local Server Testing Mode

game.Players.PlayerAdded:Connect(function(plr)
	local PhysicsService = game:GetService("PhysicsService")
	local Character = plr.Character
	local PlayerCollisionGroup = PhysicsService:CreateCollisionGroup("Players")
	PhysicsService:CollisionGroupSetCollidable(PlayerCollisionGroup, PlayerCollisionGroup, false)
	for index, value in pairs(Character:GetDescendants()) do
		if value:IsA("BasePart") then
			value.CollisionGroupId = PhysicsService:GetCollisionGroupId("Players")
		end
	end
end)

1 answer

✓ Accepted answer
game:GetService("Players").PlayerAdded:Connect(function(plr)
	local PhysicsService = game:GetService("PhysicsService")
	local Character = plr.Character
	local PlayerCollisionGroup
	local success,fail = pcall(function()
		PlayerCollisionGroup = PhysicsService:GetCollisionGroupId("Players")
	end)
	if fail then
		PlayerCollisionGroup = PhysicsService:CreateCollisionGroup("Players")
		PhysicsService:CollisionGroupSetCollidable("Players","Players",false)
	end
	for index, value in pairs(Character:GetDescendants()) do
		if value:IsA("BasePart") then
			PhysicsService:SetPartCollisionGroup(value,"Players")
		end
	end
	plr.CharacterAdded:Connect(function()
		wait(1/30)
		Character = plr.Character
		for index, value in pairs(Character:GetDescendants()) do
			if value:IsA("BasePart") then
				PhysicsService:SetPartCollisionGroup(value,"Players")
			end
		end
	end)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.