Hello!
I would like to make a door object script “open” (disappear with no animation nor collisions) for let’s say 1-hour ingame, after that, it will open for 10 seconds for the player to go thru the door and go to the next area, if the player doesn’t go thru in those 10 seconds the door closes back, resetting the timer to 1 hour again.
When the door reaches 1 hour in game time, it opens for 10 seconds for THAT person to go thru if he doesn’t go thru the door, it closes back again, and reset the loop to 1 hour and the loop “loops again”.
The player is free to stay in the beggining area without passing thru that door, the loop will restart regardless after the 10 seconds delay if he pass thru or not.
For the door touched part, this should be achievable by using a touched event on the door. You can delay a function for 10 seconds and if the door was not touched disconnect the touched event. Something like this:
local DoorConnection = nil;
local isDoorTouched = false
delay(10,function()
DoorConnection:Disconnect()
if not isDoorTouched then
warn("the door was not touched")
-- close the door
end
end)
DoorConnection = Door["Touched"]:Connect(function(Obj)
isDoorTouched = true
end)
For the waiting an hour part, I suggest a while loop and have the wait at 3600 seconds.
You can do the following
[I’m on mobile so this may take a bit to type]
[May also be errors]
local isDoorOpened = false
local DoorTouched = false
local DoorConnection = nil
while wait(3600) do
--open door
isDoorOpened = true
delay(10,function()
isDoorOpened = false
DoorConnection:Disconnect()
if not isDoorTouched then
warn("not touched")
end
end)
DoorConnection = Door["Touched"]:Connect(function()
DoorTouched = true
end)
repeat wait() until isDoorOpened = false
-- close door
end
local isDoorOpened = false
local DoorTouched = false
local DoorConnection = nil
while wait(5) do
--open door
isDoorOpened = true
delay(10,function()
isDoorOpened = false
DoorConnection:Disconnect()
if not isDoorTouched then
warn("not touched")
end
end)
DoorConnection = Door["Touched"]:Connect(function()
DoorTouched = true
end)
repeat wait() until isDoorOpened = false
-- close door
end
i changed the wait time to 5 to see if it disappear or not, the part don’t seem to do anything.
So from my understanding. It loops through an hour, everytime that hour ends, there will be a 10 second wait. If somebody goes in within the 10 seconds, the loop stops; but if nobody goes in, the timer is resetted to an hour?
When the door reaches 1 hour in game time, it opens for 10 seconds for THAT person to go thru if he doesn’t go thru the door, it closes back again, and reset the loop to 1 hour and the loop “loops again”.
The player is free to stay in the beggining area without passing thru that door, the loop will restart regardless after the 10 seconds delay if he pass thru or not.
For this scenario, use task.delay instead of delay. Task.delay of is an improved version of delay. It’s more in-sync with Roblox’s task scheduler and doesn’t throttle, therefore being more accurate.
local isDoorOpened = false
local DoorTouched = false
local DoorConnection = nil
while wait(5) do
--open door
isDoorOpened = true
task.delay(10,function()
isDoorOpened = false
DoorConnection:Disconnect()
if not isDoorTouched then
warn("not touched")
end
end)
DoorConnection = Door["Touched"]:Connect(function()
DoorTouched = true
end)
repeat wait() until isDoorOpened = false
-- close door
end
like this? but the thing is, the door/part doesn’t disappear, nothing happens, the code is not correct.
local door = path.to.door
local openTime = 10 -- how much time before opening.
local closeTime = 10 -- How much time before closing
while task.wait(openTime) do
door.Transparency = 1
door.CanCollide = false
task.delay(closeTime, function()
door.Transparency = 0
door.CanCollide = true
end)
end
The reason why your door is not disappearing is because you have no line of code that allows the door to disappear like @CodedJer said you need to first set the door transparency to 1 and can collide to false that way the player can not collide with the door and the door will be invisible
With that being said here’s some reference code to help you get started.
local door = game.workspace.part
local open_time = 10 -- how long you want the door open for before closing
local close_time = 3600 -- how long you want the door closed for before opening
while task.wait(open_time) do
door.Transparency = 1 -- this makes the door completely invisible to all the player's
door.CanCollide = false -- this will make your door not collidable to any player or object
task.delay(close_time, function()
door.Transparency = 0
door.CanCollide = true
end)
end
Hope this is what you are looking for also you may want to check if the player is a humanoid or else the script could error