Well, I didn't really understand what you wanted to do because my native language is not English and sometimes I can misinterpret what you asked, but if what you want to do is just make it so that when someone presses a button it opens a door for a certain amount of time and then closes it by itself I created it for you.
I created two templates, one I named door and the other as button, and inside the button I put a script.
Here are some variables that we will use
local button = script.Parent
local gate = script.Parent.Parent.Gate
local timeOpen = 5
local buttonPressed = false
Here we go if someone pressed the button
local function onTouch(touch)
local character = touch.Parent
local humanoid = character:FindFirstChild("Humanoid")
if humanoid and buttonPressed == false then
openGate()
end
end
button.Touched:Connect(onTouch)
So if someone pushed the button let's open our gate
local function openGate()
buttonPressed = true
gate.Transparency = 1
gate.CanCollide = false
wait(timeOpen)
gate.Transparency = 0
gate.CanCollide = true
buttonPressed = false
end
Above I gave the script order of were contrary just to explain, in the script it looks like this
local button = script.Parent
local gate = script.Parent.Parent.Gate
local timeOpen = 5
local buttonPressed = false
local function openGate()
buttonPressed = true
gate.Transparency = 1
gate.CanCollide = false
wait(timeOpen)
gate.Transparency = 0
gate.CanCollide = true
buttonPressed = false
end
local function onTouch(touch)
local character = touch.Parent
local humanoid = character:FindFirstChild("Humanoid")
if humanoid and buttonPressed == false then
openGate()
end
end
button.Touched:Connect(onTouch)
2 comments
They both had CanTouch already on.
Im sorry, i really don't know.