Hello, my last topic was about how to create a door about how to create a door that opened when you used a tool to touch it, I have now finished the script but I need to make the door go down after the key stops touching it.
I used Touched
The door is going up and down and when it says that it’s open, it’s actually closed.
I tried using BoolValues to let it know if it can open or not. Here is my script:
local waitTime = Instance.new("BoolValue")
local Ready = true
local closingVariable = true
waitTime = false -- set to false so they can open the door.
script.Parent.Touched:Connect(function(hit) -- when the key touches the door.
if hit.Parent.Name == "Key" and waitTime == false then -- if the key touched it and the boolValue is false then it will go through.
print("Door rising...") -- Prints that the part is rising as a debugger.
waitTime = true -- Set to true so you can't open the door while it's rising.
for currentCFrame = 5, 12.5, 0.05 do -- The Foor Loop to make the door rise.
wait(0.025) -- The time it takes to rise, slow.
script.Parent.CFrame = CFrame.new(0,currentCFrame,0) end
print("Door opened!")
Ready = false
closingVariable = false
script.Parent.TouchEnded:Connect(function(hit)
if hit.Parent.Name == "Key" or Ready == false and closingVariable == false then
closingVariable = false
for currentCFrame2 = 12.5,5, -0.05 do
wait(0.025) -- Again the time to go down.
script.Parent.CFrame = CFrame.new(0,currentCFrame2,0) end
print("Door can now be re-opened!") -- I used Print() to debug.
waitTime = false -- Set to false and people can open the door again.
end end) end end)
Why does this happens?