I have a question (I did not find it in tutorials) I know how to do it so that when clicking it opens a door but I do not know how I should do it so that when I click it again the door closes. I mean the script that I should use.
Thanks.
You need to create a variable that dictates whether the door is open or closed. When you first click the button, the variable should be either true or false. Then, when the door is clicked again, check to see if that variable is true/false and close the door.
For example:
local doorOpened = false
script.Parent.ClickDetector.MouseClick:Connect(function()
if doorOpened == false then
doorOpened = true
-- Open the door
else
doorOpened = false
-- Close the door
end
end)
There are many ways to go about this, have you at least any idea of what to do? You may need to touch on Roblox API.
Here is two options to go with for detecting the click:
-ClickDetector
-Mouse input (client only)
I think the question was misunderstood. I do know how to make the script to open a door when clicking, what I didn’t know was that I had to add it to the script so that when it clicked again it closed, but Surgo solved it. Thank you
Excuse me, but what is the roblox API? I never understood what it is for.
Look on the Developer Hub, and to the left side you should find API Reference.
API is for example the functions you use on instances like part & workspace and basically I call it anything specifically on Roblox’s data types and unique to Roblox’s engine.