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

How do I make a door? I want it to close and open!

Ok so can someone help me make a door? Here's what I want to do:

script.Parent.ClickDetector.MouseClick:connect(function()
	script.Parent.CanCollide = false
	wait(10)
	script.Parent.CanCollide = true
end)

but if CanCollide is false then can I make the player make it true when it clicks on it? and how?

3 answers

If Statements! Inside of your function you can make a check to see if CanCollide is true or false, and change what happens to your part depending on this. You'll want something like this:

script.Parent.ClickDetector.MouseClick:connect(function()
	script.Parent.CanCollide = not script.Parent.CanCollide
end)

It's pretty easy to follow and read, If script.Parent.CanCollide is true, then script.Parent.CanCollide is set to false, and vice versa.

If you'd like to keep that 10 second wait time, it gets a little more complicated. You'll have to set up another function to activate after your first check is made, wait 10 seconds, and then make another check to see if anything needs to be changed. Something like this:

local function timer()
	wait(10)
	if script.Parent.CanCollide == false then
		script.Parent.CanCollide = false
	end
end

script.Parent.ClickDetector.MouseClick:connect(function()
	script.Parent.CanCollide = not script.Parent.CanCollide
	timer()
end)

2 comments

1

An easier way of doing this is "script.Parent.CanCollide = not script.Parent.CanCollide" to replace lines 9 to 13.

0

Thats correct, Ill edit my code.

Make sure your door and a green button is in a Model together. Copy the script in the model.

--//Variables
local button = script.Parent.GreenButton
local door = script.Parent.Part

--//Main Function

local switch = true 

button.ClickDetector.MouseClick:connect(function()
	if switch == true then
		switch = false
		door.CanCollide = false
		door.Transparency = 1  --door opens when switch is true
		
	elseif switch == false then
		switch = true
		door.CanCollide = true
		door.Transparency = 0   -door closes when switch is closed
	
	end
end)

To do this there is a special method called debounce. You can search it up on the Roblox Wiki - it helps.

is it gonna be a clickdetector? if so

script.parent.ClickDetector.touched:connect(function()
script.parent.transparency = 1
script.parent.CanColide = true
--Do the same when they reclick. but just make it false and 0

1 comment

0

mouseclick**

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