Player Collision Group Not working

The Collision Script is not working. I have no idea why. anyhelp?

Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
for i, object in ipairs(character:GetDescendants()) do
if object:IsA(“BasePart”) then
object.CollisionGroup = “Player”
end
end
end)
end)
end) –

You can try this!

Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
for i, object in ipairs(character:GetDescendants()) do
if object:IsA(“BasePart”) then
object.CollisionGroup = tostring(player.UserId) – use a unique value
end
end
end)
end)

2 Likes

nope, doesn’t work.

extra wordsssssssssssssssssssssssss

1 Like

You didn’t even create the collision group. You need to utilize physics service.

1 Like

I think this will work!

-- [Variables] --
local Players = game:GetService("Players")

-- [Script] --
local function AddCharacter(Character:Model)
	for _, Object in ipairs(Character:GetDescendants()) do
		if (Object:IsA("BasePart") == true) then
			Object.CollisionGroup = "Player"
		end
	end
end

local function AddPlayer(Player : Player)
	AddCharacter(
		if (Player.Character ~= nil) then
			Player.Character
			else
			Player.CharacterAdded:Wait()
	)
	
	Player.CharacterAdded:Connect(AddCharacter)
end

for _, Player in ipairs(Players:GetPlayers()) do
	task.spawn(AddPlayer, Player)
end

Players.PlayerAdded:Connect(AddPlayer)

The problem was that players may have been added before you connected the .PlayerAdded event. The same also applies to the .CharacterAdded event, the players character may have loaded before you connected .CharacterAdded event.

If you have any questions please ask! :smiley::smiley::smiley:

1 Like

doesn’t work. Is it something with my collision groups?

image

2 Likes

I tested the script and it worked for me so maybe the script isn’t running? Maybe put a print statement at the start of the script and see if it prints?

1 Like

alright
i will.

extraa tetxxxxxx

1 Like

everything is printing so i’m sure its something with the collision group settings

1 Like

Is the script a server script?

1 Like

yep. It is! 000000000000000000000

Maybe it could be somethings overwriting the collision group? Try this script and see if it warns anything.

-- [Variables] --
local Players = game:GetService("Players")

-- [Script] --
local function AddCharacter(Character:Model)
	for _, Object : BasePart in ipairs(Character:GetDescendants()) do
		if (Object:IsA("BasePart") == true) then
			Object.CollisionGroup = "Player"
			print(Object.CollisionGroup)
			
			Object.Changed:Connect(function(Property)
				if (Property == "CollisionGroup") then
					warn(Object.CollisionGroup)
				end
			end)
		end
	end
end

local function AddPlayer(Player : Player)
	AddCharacter(
		if (Player.Character ~= nil) then
			Player.Character
			else
			Player.CharacterAdded:Wait()
	)

	Player.CharacterAdded:Connect(AddCharacter)
end

for _, Player in ipairs(Players:GetPlayers()) do
	task.spawn(AddPlayer, Player)
end

Players.PlayerAdded:Connect(AddPlayer)
1 Like

nope not warning anything. i don’t know what’s happening

1 Like

How are you testing the script? Are you getting another player in the game?

1 Like

no one singular plyer testing. I can test with two though.

1 Like

I would try that(using a local server) because I noticed some other CollisionGroups and those may not be working correctly, you can always check the CollisionGroup property in the properties which may help.

1 Like

used it doesn’t work. Ill try chanaging them all

1 Like

I think it is something with the default group as when I turn everything off the collisions work

2 Likes

Try putting the collision group view in list form and show us

1 Like

image
image

The mobs don’t collide with eachother

1 Like