I am currently creating a puzzle game where you move boxes on squares to open doors, but for now I'm creating a door which you click to open. Here is my code:
doorPart = script.Parent
clickDetector = doorPart.ClickDetector
doorOpen = false
clickDetector.MouseClick:connect(function()
if (doorOpen == false) then
doorOpen = true
else if (doorOpen == true) then
doorOpen = false
end
end
end)
if (doorOpen == true) then
doorPart.CanCollide = false
doorPart.Transparency = .5
else if(doorOpen == false) then
doorPart.CanCollide = true
doorPart.Transparency = 0
end
end
It used to be one big if, where it would change the CanCollide, Transparency, and doorOpen variable all at once, but that didn't work so I attempted to make 2 seperate conditional statements.
Help is greatly appreciated! Thanks!
:)

7 comments
That's not how clickdetectors work, so the script wouldn't work.
Its not the full script...
If you use a built in function (game.Workspace.Part.ClickDetector.MouseClick:Connect(function())) then it detects it every single time, not just the second the server starts.
Oh! I apologize. I see what you did now. I'd suggest you do a 'while wait() do' loop as it looks more neat.
Yeah ik that the thing is that the code from line 17 and below doesn't update when he uses the ClickDetector because its not in the clickDetector function, meaning you just have to use a loop /:
your script worked now on a standard script ;D but why would it be a Script and not a localScript? if we're getting the players mouse, isn't that client sided?
it is a local script