How To Make It Where A Player Can't Be Teleport Through A Part

So currently I have an ability that teleports the player forwards, I am doing this with CFrame. However, the player is able to tp through walls and etc. What would be a solution to this? I want it where when the player is tped, it would teleport in front of the wall, but not through it.

1 Like

I would cast a RayCast from the players position toward the position you want to teleport the player (with an offset taking the players height into consideration from the other side (teleport position)). If the RayCast returns a value other than the LocalPlayer (use filtering to filter out the player when shooting the raycast) you know there’s an object blocking the path.

You may need to cast a few rays from different positions of the player if there happens to be an object smaller than the player.

1 Like

Sorry for responding really late, I don’t have much knowledge on raycasting but wouldnt this make it where you wouldnt’ be able to tp if somethings infront of you? because I want to make it where it would tp u in front of the part instead of through it

You can get the position of where the raycast hit the object which you can use to position the player at.
Please read the documentation I gave you.

1 Like