Collision groups not working...Why?

Hi there.
I have a problem with collision groups. It doesn’t work as I would like.
When I do “PhysicsService:CollisionGroupSetCollidable(“playersTeam1”,“wall”, true)”, it doesn’t work.
However, the Editor shows that the collisions are triggered.
All parts used are CanCollide = true
If I change the CanCollide property of any part inside the character, it acts as a refresh and then it works.
Why doesn’t it work directly?

here is a video to show the problem:

script :

local PhysicsService = game:GetService("PhysicsService")

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAppearanceLoaded:Connect(function(char)		
		local hroot = char:WaitForChild("HumanoidRootPart")

		local partCollide = Instance.new("Part")
		partCollide.Name = "partCollide"
		partCollide.Parent = char
		partCollide.Size =  Vector3.new(4,5.84,2)
		partCollide.CFrame= hroot.CFrame
		partCollide.Anchored = false
		partCollide.Transparency = .5

		local weld = Instance.new("WeldConstraint")
		weld.Parent= partCollide
		weld.Part0= partCollide
		weld.Part1= hroot
		
		PhysicsService:SetPartCollisionGroup(partCollide, "playersTeam1")	
	end)
end)

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
	PhysicsService:CollisionGroupSetCollidable("playersTeam1","wall", true)
	print("Collision Group True")
end)

LocalScript (in character)

local player = game.Players.LocalPlayer
local char = script.Parent

game.UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.P then
		game.ReplicatedStorage.RemoteEvent:FireServer()
	end
end)

I noticed some weird group collision behavior. When the character jumps the collisions change.
you can see it in this video.

new script

local PhysicsService = game:GetService("PhysicsService")
PhysicsService:CollisionGroupSetCollidable("playersTeam1","wall", false)
PhysicsService:CollisionGroupSetCollidable("Default","wall", false)
PhysicsService:CollisionGroupSetCollidable("Default","playersTeam1", false)

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAppearanceLoaded:Connect(function(char)		
		local hroot = char:WaitForChild("HumanoidRootPart")

		local partCollide = Instance.new("Part")
		partCollide.Name = "partCollide"
		partCollide.Parent = char
		partCollide.Size =  Vector3.new(4,5.84,2)
		partCollide.CFrame= hroot.CFrame
		partCollide.Anchored = false
		partCollide.Transparency = .5

		local weld = Instance.new("WeldConstraint")
		weld.Parent= partCollide
		weld.Part0= partCollide
		weld.Part1= hroot
		
		PhysicsService:SetPartCollisionGroup(partCollide, "playersTeam1")	
	end)
end)

local db =true

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
	if db then
		PhysicsService:CollisionGroupSetCollidable("playersTeam1","wall", true)
		print("Collision Group True")
		player.Character.partCollide.BrickColor = BrickColor.new("Red flip/flop") 
		workspace.Wall.BrickColor = BrickColor.new("Red flip/flop") 
	else
		PhysicsService:CollisionGroupSetCollidable("playersTeam1","wall", false)
		print("Collision Group false")
		player.Character.partCollide.BrickColor = BrickColor.new("Baby blue") 
		workspace.Wall.BrickColor = BrickColor.new("Baby blue") 
	end
	db = not db
end)

Collision groups.rbxl (42,1 Ko)

I need help fast.
thank you.

1 Like

Player collisions are calculated client-side and it seems like changing whether collision groups collide with each other on the server unfortunately doesn’t update them on the client (it works as intended if the server is the network owner of the part).

Your options in this case would be to do as you did and to force a refresh, or to create a second collision group for the wall that is already set to collide with playersTeam1 and to switch the wall’s collision group when needed instead. With both options, you will need to loop through groups of parts so I recommend tagging them with CollectionService.

4 Likes

I created a new group “WallTeam1” like this.
image
And the other
image
I changed the script using
PhysicsService:SetPartCollisionGroup(workspace.Wall, “WallPlayer1”)
and
PhysicsService:SetPartCollisionGroup(workspace.Wall, “wall”)

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
	if db then
		PhysicsService:SetPartCollisionGroup(workspace.Wall, "WallPlayer1")
		print("Collision Group True")
		player.Character.partCollide.BrickColor = BrickColor.new("Red flip/flop") 
		workspace.Wall.BrickColor = BrickColor.new("Red flip/flop") 
	else
		PhysicsService:SetPartCollisionGroup(workspace.Wall, "wall")
		print("Collision Group false")
		player.Character.partCollide.BrickColor = BrickColor.new("Baby blue") 
		workspace.Wall.BrickColor = BrickColor.new("Baby blue") 
	end
	db = not db
end)

AND IT WORKS!!!
Thank you very much Runiros.
I’ve been looking for a solution for weeks.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.