Invisibility Script Error

I’m currently trying to make an admin panel and ran into an issue.

I was trying to make an invisibility command for it, so that you could click “Invisible” to go Invisible, and “Visible” to go visible. But I digress, I need help with a script. When you click the TextButton, it does makes everything but the accessories on my character disappear.

function onButtonClicked()
	game.StarterGui.ScreenGui.Click:Play()
		script.Parent.Parent.Parent.Parent.Parent.Parent.Character["Head"].Transparency = 1
		script.Parent.Parent.Parent.Parent.Parent.Parent.Character["Torso"].Transparency = 1
		script.Parent.Parent.Parent.Parent.Parent.Parent.Character["Left Arm"].Transparency = 1
		script.Parent.Parent.Parent.Parent.Parent.Parent.Character["Right Arm"].Transparency = 1
		script.Parent.Parent.Parent.Parent.Parent.Parent.Character["Left Leg"].Transparency = 1
		script.Parent.Parent.Parent.Parent.Parent.Parent.Character["Right Leg"].Transparency = 1
	end
script.Parent.MouseButton1Click:connect(onButtonClicked)

It was expectant that it would do this, as the script doesn’t include hats and whatnot, but I’m not exactly sure how to make accessories disappear and reappear.

Any assistance in this would be appreciated.

Accessories consist of the accessory object, and the Handle, a meshpart that is the actual 3D hat.
You can use a loop, which you can also use to make the limbs disappear.

local player = game.Players.LocalPlayer
local function onButtonClicked()
	game.StarterGui.ScreenGui.Click:Play()-- not sure about this, StarterGui isn't a place to store sounds
	for i,v in pairs(player.Character:GetChildren()) do
		
		if v:IsA("BasePart") then
			
			v.Transparency = 1
			
		elseif v:IsA("Accessory") then
			
			v.Handle.Transparency = 1
			
		end
		
	end
	
end
script.Parent.MouseButton1Click:Connect(onButtonClicked)

Also, making the function local is faster, and :connect is deprecated in favor of :Connect

2 Likes

I just tried your script, it didn’t work.

image

I already edited zamd157’s script and came up with a working one.

function onButtonClicked()
	local player = script.Parent.Parent.Parent.Parent.Parent.Parent
	game.StarterGui.ScreenGui.Click:Play()-- not sure about this, StarterGui isn't a place to store sounds
	for i,v in pairs(player.Character:GetChildren()) do

		if v:IsA("BasePart") then

			v.Transparency = 1

		elseif v:IsA("Accessory") then

			v.Handle.Transparency = 1

		end

	end

end
script.Parent.MouseButton1Click:Connect(onButtonClicked)

I added a local player

1 Like