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
local Time = 10
local Iterated = 0
for i = Time, 0, -1 do -- 10 is the time, change it to whatever!
if i == 0 then
task.wait(1)
Door.CanCollide = false
Door.Transparency = 1
Iterated += 1
Time = 10 * Iterated -- The wait time will add 10 each time this script goes to 0!
else
task.wait(1)
Door.CanCollide = true
Door.Transparency = 0
end
end
I do believe this should work, though it is untested! Lmk any problems you have with the code!
So this is what i did, I spawned a part then added a script with the plus icon, then pasted the code but after waiting 10 sec in the test nothing happens. how come? is the script not targeting the part?
local door = game.workspace.Door
local Time = 1
local Iterated = 0
for i = Time, 0, -1 do -- 10 is the time, change it to whatever!
if i == 0 then
task.wait(1)
door.CanCollide = false
door.Transparency = 1
Iterated += 1
Time = 10 * Iterated -- The wait time will add 10 each time this script goes to 0!
else
task.wait(1)
door.CanCollide = true
door.Transparency = 0
end
end
Ok, I figured out I had to change the Door to the part, ok, now the part does disappear but it doesn’t come back after the 10 seconds and reset itself.