What logic should I use to make a jail cell?

I have been trying to make a working jail cell for weeks now, but can’t seem to think of a valid logic! I have already gotten the main mechanics working like putting the player in the prison cell if the player is in the prisoner team and coding the open and close cell functions. Only thing I need now is for a way to detect when a player has entered the cell and for the cell to count down 7 seconds until the cell door opens.

All I am asking for is the code logic, not the code. I just need someone to help me with getting a few ideas for this logic. I hope you can help me! If you need more explanation, I am willing to give it to you!

Thank you!

One way you could do it is to put a hitbox within the jail cell, then check if a player enters it using the BasePart.Touched function thingy. When it fires it, add a delay loop like this:

i = 0
while i<7 do
    i+=1
    wait(1)
end

after the timer is done you could open the cell door

(you may also wish to utilize the BasePart.TouchEnded function to check if a player leaves the hitbox before the timer ends)

why not just

task.wait(7)

?

Just use Region3’s and ensure the player doesn’t leave that Region3, and once that event is in place, wait 7 seconds then have a CFrame move function (tween preferably, or whatever you want) for the door when the time is up and stop checking. I hope I helped! :smiley:

I was tired when I did it, I had it like that so you could add a checker to see if they leave

i = 0
while i<7 and table.find(hitbox, player.character.HumanoidRootPart) do
    i+=1
    wait(1)
end

Region3 is deprecated, you should instead be using the new OverlapParams

Yeah, that’s what I meant. Sorry lol, used to using Region3's.

1 Like

Thank you everyone for your ideas! I used Region3 to check if the player is in the cell and if so, I made the countdown start. After that, the door opens. If anyone wants to know exactly what code I used, feel free to PM me! Thanks a lot!