.Touched Event not registering with certain objects; CollisionGroups not working properly

Alright, I’ve kinda got 2 issues here.

  1. For some reason, no matter what, the doors in the game don’t register when touched by the bot, however, pretty much everything else does.

    If the .Touched event were registering properly, the bot would’ve stopped, due to the fact that the door part has a child called “IsOpen” which is a boolValue.

The Script:

for _, v in pairs(script.Parent:GetDescendants()) do
	if v:IsA("Part") or v:IsA("UnionOperation") or v:IsA("MeshPart") then
		v.Touched:Connect(function(obj)
			local isOpen = v:FindFirstChild("IsOpen")
			if isOpen ~= nil then
				script.Parent.Humanoid.WalkSpeed = 0
				wait(2.5)
				script.Parent.Humanoid.WalkSpeed = 10
			end
		end)
	end
end
  1. I have the CanCollide property on the doors set to false so that the bot can pathfind through them, however, to combat players that may simply walk through all of the doors, I have set all of the doors to be in the same CollisionGroup, and then set the Player CollisionGroup to collide with the door collision group. However, this doesn’t work for some reason. Is this just something that Roblox can’t do?

The Script:

local PhysicsService = game:GetService("PhysicsService")

PhysicsService:CreateCollisionGroup("Players")
PhysicsService:CreateCollisionGroup("Door")

for _, v in pairs(game.Workspace:GetDescendants()) do
	if v:FindFirstChild("IsOpen") ~= nil then
		PhysicsService:SetPartCollisionGroup(v, "Door") 
	end
end

PhysicsService:CollisionGroupSetCollidable("Players", "Players", false)
PhysicsService:CollisionGroupSetCollidable("Players", "Door", true)

--The player's character is set to the "Players" CollisionGroup later, and I know for sure that works through other testing.

Anyone know what to do about either of these things?

For the second one im assuming its because the script only runs once,

Maybe have a function that connects to when the door is opened then it changes the collision groups

Also, When the doors are open. Are you creating a new instance called IsOpen?
if so its probs best to just have that. and change it from true/false because if when the door closes, and deletes IsOpen, it might break some code.

For the First one, Touched events are stupid I never use them unless I have to.

What i would do is have a script that checks to see if its like 5 studs away from a closed door. waits, and then keeps moving

1 Like

Okay, for this one I actually ended up just loading doors on the client, and with some fiddling it ended up working. As for the other solution, I’m going to work on that tomorrow because I’m currently quite tired and so I’m just going to relax for the rest of the day. However, it does seem like that’s going to work.

Alright, this ended up working. Thanks for the help!

It took me an hour of fiddling and realizing that I really shouldn’t try to script when I’m tired. I messed a lot of stuff up last night that made it so that the script didn’t work properly.

1 Like