Ok, this is my last time asking for help for a while, but, I am still confused about how to make it so that the door closes after like a couple of seconds. Can someone help again?
local amountOfTimes = 35
function onClicked()
for count = 1, amountOfTimes do
script.Parent.Parent.Part.Position = script.Parent.Parent.Part.Position - Vector3.new(0.1, 0, 0)
wait(0.01)
end
end
function close()
for count = 1, amountOfTimes do
script.Parent.Parent.Part.Position = script.Parent.Parent.Part.Position + Vector3.new(0.1, 0, 0)
wait(0.01)
end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
wait(2)
script.Parent.ClickDetector.MouseClick:connect
Additionally, if you want to prevent the player from firing the MouseClick event when it’s in the process of opening and closing, you would have to add a debounce.
Ok thanks, but for real though this is my last question, sorry for asking so many questions. How do I make it so players can’t keep spam pressing the door so it keeps on moving?
local debounce = false
script.Parent.ClickDetector.MouseClick:connect(function()
if not debounce then
debounce = true
onClicked()
wait(2)
close()
debounce = false --The player can start clicking it again when this is written
end
end)