Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Door gui button?

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

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.