How to set CanCollide to false for a monster only with a script?

Hello so I have this monster and there are some tedious obstacles that are blocking the monster but I want the monster to be able to walk through and the player to not.

What I did was I tried making a script that set the cancollide to the objects in my folder called objects and adding them to a RegisterCollisionGroup so that the monster can walk through but the player cannot.

Here is my script:

```lua
-- Register the collision groups
local monsterCollisionGroupName = "MonsterCollisionGroup"
local playerCollisionGroupName = "PlayerCollisionGroup"
game:GetService("PhysicsService"):RegisterCollisionGroup(monsterCollisionGroupName)
game:GetService("PhysicsService"):RegisterCollisionGroup(playerCollisionGroupName)

-- Get the obstacles and loop through them
local obstacles = workspace.Obstacles:GetDescendants()
for _, obstacle in ipairs(obstacles) do
	if obstacle:IsA("BasePart") then
		obstacle.CollisionGroup = monsterCollisionGroupName
	end
end

-- Listen for new players
game.Players.PlayerAdded:Connect(function(player)
	-- Loop through the character's parts and set their collision group
	local character = player.Character or player.CharacterAdded:Wait()
	character:WaitForChild("HumanoidRootPart")
	local parts = character:GetDescendants()
	for _, part in ipairs(parts) do
		if part:IsA("BasePart") then
			part.CollisionGroup = playerCollisionGroupName
		end
	end
end)

How to set CanCollide to false with a script?

This title is pretty misleading, this isn’t what your asking for.

Does the monster have the same collision group? You can also use collision group editor to avoid making new collision groups.

I’m not sure since I am very unexperienced with collision groups. What you see in the script is the only thing I have.

(I didn’t even know collision groups existed about 15 minutes ago)

I’m sorry. I changed the title

As far as im aware (never used a collisiongroup…) the way they work is you create a new collisiongroup in model or via a script, and set a part to that collisiongroup and the part will only collide with parts within that collision group number

I think you’re right. If thats true can I make the players all in one collision group as well as putting the obstacles in that collision group so that the monster doesnt touch the players or the obstacles
(the monster doesnt use .Touched to attack rather magnitudes)