Ok so can someone help me make a door? Here's what I want to do:
1 | script.Parent.ClickDetector.MouseClick:connect( function () |
2 | script.Parent.CanCollide = false |
3 | wait( 10 ) |
4 | script.Parent.CanCollide = true |
5 | end ) |
but if CanCollide is false then can I make the player make it true when it clicks on it? and how?
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:
1 | script.Parent.ClickDetector.MouseClick:connect( function () |
2 | script.Parent.CanCollide = not script.Parent.CanCollide |
3 | 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:
01 | local function timer() |
02 | wait( 10 ) |
03 | if script.Parent.CanCollide = = false then |
04 | script.Parent.CanCollide = false |
05 | end |
06 | end |
07 |
08 | script.Parent.ClickDetector.MouseClick:connect( function () |
09 | script.Parent.CanCollide = not script.Parent.CanCollide |
10 | timer() |
11 | end ) |
Make sure your door and a green button is in a Model together. Copy the script in the model.
01 | --//Variables |
02 | local button = script.Parent.GreenButton |
03 | local door = script.Parent.Part |
04 |
05 | --//Main Function |
06 |
07 | local switch = true |
08 |
09 | button.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 |
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
1 | script.parent.ClickDetector.touched:connect( function () |
2 | script.parent.transparency = 1 |
3 | script.parent.CanColide = true |
4 | --Do the same when they reclick. but just make it false and 0 |