My door script isnt working!

my code:
game.workspace.Door.MouseButton1Click:connect(function(plr)
wait(5)
end)
if
game.Workspace.Door.MouseButton1Click.Triggerd then
game.Workspace.Door.Transparency = 0.5
end

The error:
MouseButton1Click is not a valid member of Part “Workspace.Door”

Screenshots of the door in the explorer tab:
image

Uhhh, first of all MouseButton1Click is an event that triggers when the person clicks.

2nd of all, you aren’t even referencing the ClickDetector. I’m pretty sure its MouseClick, not MouseButton1Click, and I recommend you do not put this in a server script if you do not want it to open for other players.

1 Like

You’d need to reference the ClickDetector:

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
   wait(5);
   -- Do More stuff here.
end)

-- Anything here will only be executed once.
1 Like

Certainly, the API doesn’t exist on ClickDetector and you’re confusing it with a GUI button’s API. Use MouseClick. To appropriately rewrite this simple mechanic:

workspace.Door.MouseClick(function(plr) -- this only turns the transparency
    workspace.Door.Transparency = 0.5
    wait(5) -- why is this here
end)

Elaborate script is here:

local isOpen, isToggling

workspace.Door.MouseClick(function(plr) 
    if isToggling then -- debounce
        return
    end
    isToggling = true

    if not isOpen then -- if statement, separating opposing settings
        workspace.Door.CanCollide = false
        workspace.Door.Transparency = 0.5
    else
        workspace.Door.CanCollide = true
        workspace.Door.Transparency = 0
    end
    wait(5)
    isToggling = false
end)
1 Like

PS:

This is like my 5th time actually coding somthing by myself. and my friend told me that i got it mixed up at school today. thanks for the help!