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

Turn a object visible and invisible in one button?

Asked by 5 years ago
Edited 5 years ago

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

Log in to vote
1
Answered by
Creacoz 210 Moderation Voter
5 years ago
Edited 5 years ago

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)
0
Did it work :D? If so can you accept my answer it would be appreciated uwu Creacoz 210 — 5y
Ad
Log in to vote
1
Answered by 5 years ago

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

Log in to vote
0
Answered by 5 years ago

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.

Answer this question