Do take note that the function within the script they provided will automatically change the CanCollide and Transparency values back to its “closed” state, as shown below.
Because there is nothing stopping or delaying the function from changing the door’s properties back in the latter half of the function, you won’t have any time, realistically, to go through the door. I’ve gone back to correct some mistakes I made in my original reply while substituting your original references for variables I created, along with some additional explanations as to how it works:
local door = script.Parent -- This turns "door" into a variable. Whenever you type "door" in this script, it will mean script.Parent.
door.ClickDetector.MouseClick:Connect(function() -- Runs the function when the door is clicked.
if door.CanCollide == true then -- If the door is closed (CanCollide = true) then...
door.CanCollide = false -- The door opens!
door.Transparency = 0.75 -- The door becomes almost completely invisible.
-- I would suggest maintaining partial visibility so that players know there's a door and not just a doorframe.
local Open = door.Open -- This defines "Open" as the sound effect called "Open" inside of the door
Open:Play() -- This plays the sound called "Open"
elseif door.CanCollide == false then -- If the door was NOT open when someone clicked it (CanCollide = true), then...
door.CanCollide = true -- The door closes!
door.Transparency = 0 -- The door becomes entirely visible
local Close = door.Close -- This defines "Close" as the sound effect called "Close" inside of the door
Close:Play() -- This plays the sound called "Close"
end -- Ends the "if then" statement. Each "if then" statement needs an end.
end) -- Ends the function. Each function needs an end.
This is basically the same thing that I mentioned the other day, but I fixed one part where I put “door.Parent.Transparency”, which didn’t reference the door properly. I also removed door2 because I’ve just rewritten this for the example of a clickable door that opens and closes. However, this could be spammed, so we could add something called “debounce” to the script which will prevent an overflow of inputs. This is something that you will most commonly start to use when utilizing the .Touched event.
local door = script.Parent -- This turns "door" into a variable. Whenever you type "door" in this script, it will mean script.Parent.
local debounce = false -- Makes our imaginary variable called "debounce" set to false. You can name it whatever you want.
door.ClickDetector.MouseClick:Connect(function() -- Runs the function when the door is clicked.
if debounce == false -- If our variable is set to false, then...
then debounce = true -- It will be set to true.
if door.CanCollide == true then -- If the door is closed (CanCollide = true) then...
door.CanCollide = false -- The door opens!
door.Transparency = 0.75 -- The door becomes almost completely invisible.
-- I would suggest maintaining partial visibility so that players know there's a door and not just a doorframe.
local Open = door.Open -- This defines "Open" as the sound effect called "Open" inside of the door
Open:Play() -- This plays the sound called "Open"
elseif door.CanCollide == false then -- If the door was NOT open when someone clicked it (CanCollide = true), then...
door.CanCollide = true -- The door closes!
door.Transparency = 0 -- The door becomes entirely visible
local Close = door.Close -- This defines "Close" as the sound effect called "Close" inside of the door
Close:Play() -- This plays the sound called "Close"
end -- Ends the "if then" statement. Each "if then" statement needs an end.
end -- Ends the other "if then" statement. Take note that "elseif"s do not need their own end.
debounce = false -- Our varible will be set to false to make sure it runs properly the next time it is clicked.
end) -- Ends the function. Each function needs an end.
In this case, “Debounce” is technically imaginary and doesn’t actually have to do anything with the door’s functionality, as the door would still work without it. However, by including debounce, you can greatly reduce the amount of inputs that are sent. If you would like to test this, try using the first script that I provided in this comment and then spam click the door to open and close it. Afterwards, replace it with this second one and you will notice the difference.
Anyway, hope that this has been more useful for you! The trial and error approach can be great in many different instances, and while it won’t help with learning everything, it’s definitely a great strategy that can allow you to further improve upon your development skills and general life skills without having to spend the time in certain instances to look around for an answer. Just remember that it’s good to reference places where it has been answered (when needed) just so you don’t dig yourself into a hole of bad habits! Best of luck on your development journey! 