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)