Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Help scripting a locker door opening?

I need to open and close lockers, and I need help. This is what I have so far, I've been working on this code for quite a while, and I'm stumped.

game.Workspace.Part: open()

1 comment

0

Add some common sense to it.

1 answer

Haha. Silly dude, that's not how lua works! So first of all we will need a function which opens the door. I would suggest to make it invisible and make it so you can go through it.

game.Workspace.Part.Transparency = 1
game.Workspace.Part.CanCollide = false

Alright, let's run the game.

What happened? The door just vanished.

You will need to add a function to WHEN it will open. Let's use ClickDetector this time. We will use the event called MouseClick

So, insert a ClickDetector into the door and enter the following script into the door.

function Open() -- this is the door open function
	game.Workspace.Part.Transparency = 1
	game.Workspace.Part.CanCollide = false
end

game.Workspace.Part.ClickDetector.MouseClick:connect(Open) -- when the part is clicked activate the Open() function

Voila! But wait! Now you can't close the door?

In order to do that we will need to make a variable called open local open = false

When the open variable is false, we are going to open the door and change the variable to true. Otherwise we will close the door and change the variable to false.

This will be the script.

local open = false -- the variable

function Open() -- this is the door open function
	if open == false then -- check if the variable is false
		game.Workspace.Part.Transparency = 1
		game.Workspace.Part.CanCollide = false
	else -- otherwise
		game.Workspace.Part.Transparency = 0
		game.Workspace.Part.CanCollide = true -- do the exact opposite of what we did to open the door
	end -- end the if statement
end

game.Workspace.Part.ClickDetector.MouseClick:connect(Open) -- when the part is clicked activate the Open() function

I reccomend you using the ROBLOX wiki or some YouTube tutorials to learn how the Lua actually works! Hope I helped. Byeee!

This discussion is preserved as it was. New answers, comments, and votes are closed.