How do you make a door open after X amount of time has passed?

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! :grin:


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.

while true do 
wait(settimehere) 
script.Parent.Transparency = 1 
script.Parent.CanCollide = false 
wait(10) 
script.Parent.Transparency = 0 
script.Parent.CanCollide = true 
wait(settime) 
end

Anything like this?

What ive made is a very much simpler way of doing what you said.

1 Like

This will double set time i think you ment

while task.wait(setTimeHere) do 
 script.Parent.Transparency = 1 
 script.Parent.CanCollide = false 
 task.wait(10) 
 script.Parent.Transparency = 0 
 script.Parent.CanCollide = true 

end

Yeah close, it works but the door doesn’t come back after it disappear I want it so it comes back and start the loop over.

Were you trying to reply to @CodedJer? My script should work fine.

Oh, it does work I tried it now, that’s cool, now all it needs is that the door collisions only affect the player that waited the 1 hour mark and not everyone in the server so someone could cheese the time of the door, is that possible to be done?

did you put this as a local script or something? if not, i have no idea why it could be doing this.