PhysicsService Collisions

Hello there!

I have made a sliding door using PrismaticConstraints. Normally, the door works perfectly. I had a problem with Collisions since the door could collide with everything and couldn’t open properly.
I have made it to not collide with the default group but with the players. I made it not collide with the default group and I created a special collision group for players.

ServerScriptService Script:

local PhysicsService = game:GetSerive("PhysicsService")
PhysicsService:CreateCollisionGroup("Door")
PhysicsService:CreateCollisionGroup("Player")
PhysicsService:CollisionGroupSetCollidable("Door", "Door", false)
PhysicsService:CollisionGroupSetCollidable("Door", "Default", false)
PhysicsService:CollisionGroupSetCollidable("Door", "Player", true)

game.Players.PlayerAdded:Connect(function(player)
     player.CharacterAdded:Connect(function(character)
          for _, v in pairs(character:GetDescendants()) do
               if v:IsA("Part") or v:IsA("MeshPart") then
                    PhysicsService:SetPartCollisionGroup(v, "Player")
               end
          end
     end)
end)

Besides the keycard scanners, the door has a remote opener, which is a Tool. The door has a RemoteEvent in it. When fired, the door will open.
After I made it to not collide with the default group, and I tried to open it with the remote, the RemoteEvent was never fired. After I made it collide with the default group again, the RemoteEvent was fired.

Here is the Remote Tool LocalScript:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local UserInputService = game:GetService("UserInputService")
local Equipped = false
local Connection;
local Connection2;

function Check(tofire)
	if Mouse.Target:FindFirstChild("RemoteEvent") then
		Mouse.Target.RemoteEvent:FireServer(tofire)
	elseif
		Mouse.Target.Parent:FindFirstChild("RemoteEvent") then
			Mouse.Target.Parent.RemoteEvent:FireServer(tofire)
	elseif
		Mouse.Target.Parent.Parent:FindFirstChild("RemoteEvent") then
			Mouse.Target.Parent.Parent.RemoteEvent:FireServer(tofire)
	elseif
		Mouse.Target.Parent.Parent.Parent:FindFirstChild("RemoteEvent") then
			Mouse.Target.Parent.Parent.Parent.RemoteEvent:FireServer(tofire)
	elseif
		Mouse.Target.Parent.Parent.Parent.Parent:FindFirstChild("RemoteEvent") then
			Mouse.Target.Parent.Parent.Parent.Parent.RemoteEvent:FireServer(tofire)
	elseif
		Mouse.Target.Parent.Parent.Parent.Parent.Parent:FindFirstChild("RemoteEvent") then
			Mouse.Target.Parent.Parent.Parent.Parent.Parent.RemoteEvent:FireServer(tofire)
	end
end

script.Parent.Equipped:Connect(function()
	Connection = Mouse.Button1Down:Connect(function()
		local S, E = pcall(function()
			Check("ToggleDoor")
		end)
	end)
	Connection2 = Mouse.Button2Down:Connect(function()
		local S, E = pcall(function()
			Check("ToggleLockdownStatus")
		end)
	end)
end)

script.Parent.Unequipped:Connect(function()
	Connection:Disconnect()
	Connection2:Disconnect()
	Connection = nil
	Connection2 = nil
end)

CONCLUSION: If the door’s collision group can not collide with the Default one and I click with the remote on the door, it will not work. Else, if the door’s collision group can collide with the Default one and I click with the remote on the door, it will fire the RemoteEvent located within the door.

My concern is what is causing this issue and how I should fix it?

1 Like

I think you need to make what the issue is a lot more clear.

1 Like

Hello Nezuo,
Thank you for your answer. I’ll try to explain as good as I can.

If a Part has a CollisionGroup that does not collide with the “Default” CollisionGroup, Mouse.Target will ignore that Part.
If the Part can collide with the “Default” CollisionGroup, Mouse.Target will not ignore that Part. Here’s a short video:

The CollisionGroup called “Door” can not collide with the “Default” CollisionGroup. The part with CollisionGroup “Door” is called Part1, the part with CollisionGroup “Default” is called Part2.

Regarding this problem:

If the door’s collision group can not collide with the Default one and I click with the remote on the door, it will not work.

Raycasts (and things that use it, such as Mouse.Target) will ignore parts that are in a CollisionGroup that can’t collide with Default.
https://developer.roblox.com/en-us/api-reference/function/Workspace/FindPartOnRay

Instead of collision groups for this, could you use the new NoCollisionConstraint instead? Two things connected by the NoCollisionConstraint will not collide with each other. You can make use this to make it so that the door and the frame don’t collide with each other.

3 Likes