Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago

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

1script.Parent.ClickDetector.MouseClick:connect(function()
2    script.Parent.CanCollide = false
3    wait(10)
4    script.Parent.CanCollide = true
5end)

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

3 answers

Log in to vote
0
Answered by
Jellyfosh 125
7 years ago
Edited 7 years ago

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:

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

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:

01local function timer()
02    wait(10)
03    if script.Parent.CanCollide == false then
04        script.Parent.CanCollide = false
05    end
06end
07 
08script.Parent.ClickDetector.MouseClick:connect(function()
09    script.Parent.CanCollide = not script.Parent.CanCollide
10    timer()
11end)
1
An easier way of doing this is "script.Parent.CanCollide = not script.Parent.CanCollide" to replace lines 9 to 13. UgOsMiLy 1074 — 7y
0
Thats correct, Ill edit my code. Jellyfosh 125 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

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

01--//Variables
02local button = script.Parent.GreenButton
03local door = script.Parent.Part
04 
05--//Main Function
06 
07local switch = true
08 
09button.ClickDetector.MouseClick:connect(function()
10    if switch == true then
11        switch = false
12        door.CanCollide = false
13        door.Transparency = 1  --door opens when switch is true
14 
15    elseif switch == false then
View all 21 lines...

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

Log in to vote
0
Answered by 7 years ago

is it gonna be a clickdetector? if so

1script.parent.ClickDetector.touched:connect(function()
2script.parent.transparency = 1
3script.parent.CanColide = true
4--Do the same when they reclick. but just make it false and 0
0
mouseclick** lopehole12 0 — 7y

Answer this question