How would I use Collision Groups but in reverse?

Let me explain.

I have an area of the map where I do not want to allow vehicles, but players are allowed, it would be super helpful if I could put a wall up and set it to CanCollide false, except that vehicles can still collide with the wall but everything else can pass through it.

Any idea how I would make this?

If CanCollide is false, nothing will collide with the part regardless of its Collision Group. I would say to just make a new collision group for vehicles, and a new collision group for the wall that only collides with vehicles.

2 Likes

If you really need the part to be CanCollide false, you could try to make a part detector that sets CanCollide true when It finds a vehicle.

Something like:

function onTouch(hit)
   if hit.Parent.Name == "Vehicle" then 
      script.Parent.CanCollide = true
   end
end)

But the best option It’s to do It by using Collisions Groups.

I wouldn’t recommend doing this. There will always be a delay on the server and the car will end up going a bit through the wall and once you set the part’s CanCollide to true, the car might get stuck/flung. (or even worse)

It’s best to use Collision Groups just like everybody else said. There’s no such thing as Collission Groups in “reverse”, what you’re talking about is Collission Groups itself.

I think what you are trying to do is simply an invisible CanCollide true wall, and add the characters parts (each time they are added to the player by the CharacterAdded event) to a collision group with the wall and set the collision to false.

Make sure to use GetDescendants on the character to get all parts, mesh parts, etc, to include accoutrements, tools, and anything else in the scope of the character.

If you have pets or anything outside the scope of the character that follows the character or needs to go through the wall as well, that will need to be added to the collision group too.

I took a different approach and solved the issue. The vehicle was a raft and instead of preventing the raft from hitting land I added a way to push the raft if it should ever get stuck on land.

3 Likes