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 6 years ago

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

Log in to vote
0
Answered by
Jellyfosh 125
6 years ago
Edited 6 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:

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)

1
An easier way of doing this is "script.Parent.CanCollide = not script.Parent.CanCollide" to replace lines 9 to 13. UgOsMiLy 1074 — 6y
0
Thats correct, Ill edit my code. Jellyfosh 125 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

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.

Log in to vote
0
Answered by 6 years ago

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
0
mouseclick** lopehole12 0 — 6y

Answer this question