i am very new (like really new) at lua scripting and i read some basics and this is the code i came up with
function OnClicked(playerWhoClicked) game.Workspace.Doors.Door1.Transparency= 1 game.Workspace.Doors.Door2.Transparency= 1 game.Workspace.Doors.Door3.Transparency= 0 game.Workspace.Doors.Door4.Transparency= 0 game.Workspace.Doors.Door1.CanCollide= false game.Workspace.Doors.Door2.CanCollide= false game.Workspace.Doors.Door3.Cancollide= true game.Workspace.Doors.Door4.Cancollide= true wait(3) game.Workspace.Doors.Door1.Transparency= 0 game.Workspace.Doors.Door2.Transparency= 0 game.Workspace.Doors.Door3.Transparency= 1 game.Workspace.Doors.Door4.Transparency= 1 game.Workspace.Doors.Door1.CanCollide= true game.Workspace.Doors.Door2.CanCollide= true game.Workspace.Doors.Door3.Cancollide= false game.Workspace.Doors.Door4.Cancollide= false end
it doesn't work so can someone help me out? yes i know it's really bad
Oh, I see the problem. For the CanCollide properties in the script, you HAVE to uppercase CanCollide or else the script won't work. Lua is very sensitive and if you make even one grammar mistake in the script, it won't run.
Your script before:
function OnClicked(playerWhoClicked) game.Workspace.Doors.Door1.Transparency= 1 game.Workspace.Doors.Door2.Transparency= 1 game.Workspace.Doors.Door3.Transparency= 0 game.Workspace.Doors.Door4.Transparency= 0 game.Workspace.Doors.Door1.CanCollide= false game.Workspace.Doors.Door2.CanCollide= false game.Workspace.Doors.Door3.Cancollide= true -- Error. Has to be "CanCollide" game.Workspace.Doors.Door4.Cancollide= true -- Error. Has to be "CanCollide" wait(3) game.Workspace.Doors.Door1.Transparency= 0 game.Workspace.Doors.Door2.Transparency= 0 game.Workspace.Doors.Door3.Transparency= 1 game.Workspace.Doors.Door4.Transparency= 1 game.Workspace.Doors.Door1.CanCollide= true game.Workspace.Doors.Door2.CanCollide= true game.Workspace.Doors.Door3.Cancollide= false -- Error. Has to be "CanCollide" game.Workspace.Doors.Door4.Cancollide= false -- Error. Has to be "CanCollide" end -- You forgot a part here. It's the most important part of the script.
What your script should look like:
H = game.Workspace.Doors -- I just added a little shortcut. It's optional if you want to add it. It just makes scripting easier. function OnClicked(playerWhoClicked) H.Door1.Transparency= 1 H.Door2.Transparency= 1 H.Door3.Transparency= 0 H.Door4.Transparency= 0 H.Door1.CanCollide= false H.Door2.CanCollide= false H.Door3.CanCollide= true -- Fixed grammar mistake H.Door4.CanCollide= true -- Fixed grammar mistake wait(3) H.Door1.Transparency= 0 H.Door2.Transparency= 0 H.Door3.Transparency= 1 H.Door4.Transparency= 1 H.Door1.CanCollide= true H.Door2.CanCollide= true H.Door3.CanCollide= false -- Fixed grammar mistake H.Door4.CanCollide= false -- Fixed grammar mistake end script.Parent.ClickDetector.MouseClick:connect(onClicked) -- This is the most important part of the script. It won't run without this.
So basically, your script only had 5 problems in it. To make the script really work, you have to add a ClickDetector into each of the parts, which are the doors.
Hope this helped! - Im new too bro.
You forgot script.Parent.Clicked:connect(onClicked)
function OnClicked(playerWhoClicked) game.Workspace.Doors.Door1.Transparency= 1 game.Workspace.Doors.Door2.Transparency= 1 game.Workspace.Doors.Door3.Transparency= 0 game.Workspace.Doors.Door4.Transparency= 0 game.Workspace.Doors.Door1.CanCollide= false game.Workspace.Doors.Door2.CanCollide= false game.Workspace.Doors.Door3.Cancollide= true game.Workspace.Doors.Door4.Cancollide= true wait(3) game.Workspace.Doors.Door1.Transparency= 0 game.Workspace.Doors.Door2.Transparency= 0 game.Workspace.Doors.Door3.Transparency= 1 game.Workspace.Doors.Door4.Transparency= 1 game.Workspace.Doors.Door1.CanCollide= true game.Workspace.Doors.Door2.CanCollide= true game.Workspace.Doors.Door3.Cancollide= false game.Workspace.Doors.Door4.Cancollide= false end script.Parent.Clicked:connect(onClicked)
function OnClicked(playerWhoClicked) game.Workspace.Doors.Door1.Transparency= 1 game.Workspace.Doors.Door2.Transparency= 1 game.Workspace.Doors.Door3.Transparency= 0 game.Workspace.Doors.Door4.Transparency= 0 game.Workspace.Doors.Door1.CanCollide= false game.Workspace.Doors.Door2.CanCollide= false game.Workspace.Doors.CanCollide= true game.Workspace.Doors.Door4.CanCollide= true wait(3) game.Workspace.Doors.Door1.Transparency= 0 game.Workspace.Doors.Door2.Transparency= 0 game.Workspace.Doors.Door3.Transparency= 1 game.Workspace.Doors.Door4.Transparency= 1 game.Workspace.Doors.Door1.CanCollide= true game.Workspace.Doors.Door2.CanCollide= true game.Workspace.Doors.Door3.CanCollide= false game.Workspace.Doors.Door4.CanCollide= false end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
--Put a ClickDetector in the brick + Keep name as ClickDetector