Invisible Button

Hello, I know I’ve uploaded recently but again I need help with something.

local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
char = player.Character
char.Head.Transparency = 1
char.Torso.Transparency = 1
char[“Left Arm”].Transparency = 1
char[“Left Leg”].Transparency = 1
char[“Right Arm”].Transparency = 1
char[“Right Leg”].Transparency = 1
char.Head.face.Transparency = 1
for i,v in pairs(char:GetChildren()) do – This is to go through things like hair, wings, etc.
if v.ClassName == “Accessory” then
v.Handle.Transparency = 1
end
end
end)

This is the code I have found from somewhere to make somebody go invisible if they click a TextButton in a StarterGui.
image

I want to make it so that if you click it once it makes all the limbs on an R15 character disappear but if you press it again they re-appear. Many thanks to anybody who can help.

1 Like

I have remade your code to make it invisible.

ocal player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
char = player.Character
char.Head.Transparency = 1
char.Torso.Transparency = 1
char[“Left Arm”].Transparency = 1
char[“Left Leg”].Transparency = 1
char[“Right Arm”].Transparency = 1
char[“Right Leg”].Transparency = 1
char.Head.face.Transparency = 1
for i,v in pairs(char:GetChildren()) do – This is to go through things like hair, wings, etc.
script.Parent.Visible = false --Makes the box invisible.
if v.ClassName == “Accessory” then
  v.Handle.Transparency = 1
end
end
end)

But how would they then click that button again to make the limbs re-appear?

You would have another button, and make that button visible, so script.Parent.Parent.Button2.Visible = true, and then when the player clicks that button, everything becomes visible, and that button becomes invisible, and then the button that we previously made invisible becomes visible again.

One thing I would like to say here, you can simply use a GetDescendants loop on the character for the bodyparts, rather than setting then individually,

script.Parent.Activated:Connect(function()
   for _,part in next,char:GetDescendants() do
      if part:IsA("BasePart") do
         part.Transparency = 1
      end
   end
end)

To make this toggleable, you can use a simply ternary operator

script.Parent.Activated:Connect(function()
for _,part in next,char:GetDescendants() do
      if part:IsA("BasePart") do
         part.Transparency = (part.Transparency == 0 and 1 or 0)
      end
   end
end)

Where would this code come into the script? I’m having some problems implementing it

Could you send a download to the GUI? I’ll do this for you! :smiley: --I no longer need your GUI, you could just use this script :wink:
I’ve created this simple script for you, combining what @theking48989987 provided we are able to create this;
https://i.gyazo.com/7e6802ae51740b9ee236d152b8c5c3ad.mp4

Here is the code, I made it so you wont have to make 2 TextButtons, and you could just stick to one!

local player = game.Players.LocalPlayer
local invis = false
local char = player.Character
script.Parent.MouseButton1Click:Connect(function()
if invis == false then
  dissapear()
elseif invis == true then
  reappear()
end
end)
function dissapear()
  if invis == false then
    for _,part in next,char:GetDescendants() do
      if part:IsA("BasePart") then
        part.Transparency = 1
        invis = true
        script.Parent.Text = "Visible"
		char.Head.face.Transparency = 1
      end
    end
  end
end
function reappear()
  if invis == true then
    for _,part in next,char:GetDescendants() do
      if part:IsA("BasePart") then
        part.Transparency = 0
        invis = false
        script.Parent.Text = "Invisible"
        char.HumanoidRootPart.Transparency = 1
		char.Head.face.Transparency = 0
      end
    end
  end
end

Hope I helped. :smiley:

1 Like

Darn, I just realized that it would have to be filtering enabled since it would only be client side otherwise… I’m so sorry that I didn’t mention this

Simple! You can use a remote event, and fire the server , it would then find the players character, and do the same thing, would you like the code for this?

Yeah, I hate to ask for it but I have quite limited scripting knowledge.

(Client) Put this in your text button

local player = game.Players.LocalPlayer
local invis = false
local char = player.Character
script.Parent.MouseButton1Click:Connect(function()
if invis == false then
  dissapear()
elseif invis == true then
  reappear()
end
end)
function dissapear()
  if invis == false then
    game.ReplicatedStorage.Event:FireServer(invis)
    invis = true
    script.Parent.Text = "Visible"
  end
end
function reappear()
  if invis == true then
    game.ReplicatedStorage.Event:FireServer(invis)
    invis = false
    script.Parent.Text = "Invisible"
  end
end

(Server) Create a Script, put it in ServerScriptService, here is the code;

game.ReplicatedStorage.Event.OnServerEvent:Connect(function(Player,status)
local char = Player.Character
if status == true then
  reappear(char)
elseif status == false then
  dissapear(char)
end
end)
function dissapear(char)
  for _,part in next,char:GetDescendants() do
    if part:IsA("BasePart") then
      part.Transparency = 1
      char.Head.face.Transparency = 1
    end
  end
end
function reappear(char)
  for _,part in next,char:GetDescendants() do
    if part:IsA("BasePart") then
      part.Transparency = 0
      char.HumanoidRootPart.Transparency = 1
      char.Head.face.Transparency = 0
    end
  end
end

For the RemoteEvent, just create a new RemoteEvent instance in ReplicatedStorage and name it Event.
image
This Thread will be useful for you in the future to learn about RemoteEvents and RemoteFunctions;

3 Likes