How to teleport players in an incorrect spot to a place they are supposed to be efficiently?

Hello! I can already do this, but I already know the way i’m doing it is very sloppy and can be easily bypassed by just standing still during the duration of when it is open. This will all make sense very soon.
(i am pretty sure this isnt code review)
Everyone is supposed to walk into an area, and the door closes. Of course, not all of the players are going to walk into the area because they are trying to break the game. So what I have been doing is making a part the size of the room they are not supposed to be in, and when I do not want them in that room anymore the script inside of the part will become enabled by just doing teleporter.script.disabled = false. I know that the way I have been doing this is not very secure because if you stand completely still in the duration that the script is enabled, you will not be teleported. I know there is probably another way of doing this that will 100 percent guarantee the player gets removed from the room even if they are standing still but I just do not know how I can.

Oh and also, the script inside of teleporter is a teleport ontouched script I made that teleports all the players to a part called TeleExit. I move this Exit around using positions so I do not need multiple teleporter exits, and all of the teleporters go to that one Exit

Thank you for the help and suggestions! Sorry if this is hard to read aswell.

1 Like

If it were me I would just get every player’s character position when the door fully closes, then just check the position boundaries for everyone (like checking the players position is within the X, Y, & Z boundaries)

ok what you can do:

1: - in the teleporter script make the part that is size of the size of the area they are not suppose to be in collideable. So you should set can collide to true.
2 - then use the :GetTouchingPartsFunction() instead of the touched event

local part = -- this is the part that encompasses the area the player should not be in
part.CanCollide = true--this must be done before you call the GetTouchingParts function
local touchingParts = part:GetTouchingParts()
for _,touchingPart in pairs(touchingParts)do
     if touchingPart:FindFirstChild("Humanoid") then--this checks if the touching part is a character
         local character = touchingPart
         character:MoveTo(TeleExit.Position)
     end
end

this solution is more safe than the one you are currently implementing, also instead of changing the disabled property of the script you can just use the wait() function

local DURATION = 5 -- this is how long in seconds you want to wait until moving the players not in the room
wait(DURATION)
--put the code above in this area

Thank you both for the answers! I think I will be going with @RomeoEDD’s reply because it better suits my game. @greenboo5 Thanks for the ideas though! If what Romeo said doesn’t work out I will be using your reply to help me.