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.
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.
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)
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)
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
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?
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.
This Thread will be useful for you in the future to learn about RemoteEvents and RemoteFunctions;