I tried to make a door but the script won't work

so i tried to make a door in my game but the script won’t work (i am a beginner)

6 Likes

Use the clickdetector to detect for a click Part.Clickdetector.MouseClick and that if statement is useless

Hey, this is not quite how scripting works. I’m on my phone rn but I can guide you on how to make this work

Yes, you would need a click detector on the part, you would also need variables in the script to tell if the door is open or not

He does have a click detector as you can see in the explorer he just didn’t know how to use it right

local part = script.Parent
local bool = false

part.ClickDetector.MouseClick:Connect(function()
        if bool == false then
              part.Transparency = 0.5
              part.CanCollide = false
              bool = true
        elseif bool == true then
              part.Transparency = 0
              part.CanCollide = true
              bool = false
        end
end)

Explanation:

bool is a variable that answer is false as default.
Use bool as a Toggle Door.
Your location of MouseClick Event is wrong.
You don’t need statements, use bool statements as toggle.
If you click door, it turns into true and do what the script on statement says.
Use elseif as toggle. Checks when the Bool is a true.
Why checking if bool is true? Because when you click a door, it turns true.
So click again so it turns false.

I’m bad at english, I hope you can understand it.

4 Likes
local Click = script.Parent.ClickDetector


function open()
   ...
end

Click.MouseClick:Connect(open)

Im on phone so cant write everything.

1 Like

You don’t need to use elseif bool == true. You can just use else because Bool can be either true or false.

1 Like
Local clicker = script.Parent.ClickDetector
Local open = false

clicker.Mouseclick:connect(function ()--detect when the clicker is clicked
if open == false then
open = true
--change part here
else
open = false
--change part here
end)
2 Likes