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

Turn a object visible and invisible in one button?

I am testing how to make a object be invisible and visible when clicked. Example , I click it once it will be invisible then I click it again it would be visible.

Door = script.Parent.Parent

function pie()
	if Door.p1.Transparency == 1 then
		Door.p1.Transparency = 0
	else
		Door.p1.Transparency = 1
	end
end

script.Parent.MouseButton1Click:connect(function(pie)

The door is called "p1" This is inside a script not a local one.

3 answers

✓ Accepted answer

When you want a function to be connected you don't do

script.Parent.MouseButton1Click:connect(function(pie)

that automatically creates a function. try :

script.Parent.MouseButton1Click:Connect(pie)

If it's a clickdetector it would be

script.Parent.ClickDetector.MouseClick:Connect(pie)

1 comment

0

Did it work :D? If so can you accept my answer it would be appreciated uwu

The door can't be called p1, Because the game recognizes it as a number and not a name (String) so you need to rename it.

MajinBluee

Because i'm assuming this is a TextButton or ImageButton, it's a little more tough than that.

space = game.Workspace -- connects workspace to gui.
Door = space.Door -- asumming door is a model. if not, or if it's different, edit it here.

function onClicked()
   if Door.Transparency == 0 then
      Door.Transparency = 1
      else
         Door.Transparency = 0
  end
end

script.Parent.MouseButton1Click:connect(onClicked)

If i'm wrong, please tell me why, I haven't tested this. this should work though. It will not work, if your putting your model or door or part inside StarterGui, as this does nothing. The only reason you would put it in there is for grabbing and moving inside explorer reasons.

Also make sure this script is a LocalScript inside the TextButton or ImageButton.

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