Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Door gui button?

Asked by 10 years ago

Alright trying to make a door where if you click 1 button it will make it appear and press that button again the door will go away.

``~~~~~~~~~~~~~~~~~

function onButtonClicked()
goo = game.Lighting.MainDoor:clone()
goo2 = game.Lighting.Outer:clone()
goo.Parent = Workspace
goo:MakeJoints()
goo2.Parent = Workspace
goo2:MakeJoints()
end
script.Parent.MouseButton1Down:connect(onButtonClicked)

~~~~~~~~~~~~~~~~~ `` Well I have that so far I think that will work to make it come but I am unsure how to do it so if clicked again it will get removed from workspace. ?

Thats all,

1 answer

Log in to vote
0
Answered by 10 years ago

To do it, you need to make it check to see if you have clicked the button, and then it should decide whether it is removing it or creating it. Something like this should suffice:

local Clicked = false
function onButtonClicked()
    local goo = game.Lighting.MainDoor:clone()
    local goo2 = game.Lighting.Outer:clone()
    if Clicked == false then
        goo.Parent = Workspace
        goo:MakeJoints()
        goo2.Parent = Workspace
        goo2:MakeJoints()
        Clicked = true
    elseif Clicked == true then
        pcall(function()
            Workspace[goo.Name]:Destroy()
            Workspace[goo2.Name]:Destroy()
        end)
        Clicked = false
    end
end
script.Parent.MouseButton1Down:connect(onButtonClicked)
Ad

Answer this question