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?
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)
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