It works but there is two problems with it, one, it doesn't make hats and faces invisible too and two, when I toggle back to visible then it adds a grey block around the players torso.
local event = script.InvisFunction
local Val = script.Parent.Hidden.Value
event.OnServerEvent:Connect(function(player)
if Val == false then
Val = true
local character = player.Character or workspace:FindFirstChild(player.Name)
for k, v in pairs(character:GetChildren()) do
if v:IsA('BasePart') then
v.Transparency = 1
local decal = v:FindFirstChild('Decal')
if decal then
decal.Transparency = 1
end
end
end
else
Val = false
local character = player.Character or workspace:FindFirstChild(player.Name)
for y, t in pairs(character:GetChildren()) do
if t:IsA('BasePart') then
t.Transparency = 0
local decal = t:FindFirstChild('Decal')
if decal then
decal.Transparency = 0
end
end
end
end
end)

3 comments
What kind of toggle invisibility? Making other people invisible? or making every one?
A button that you click to make yourself invisible but shows for everyone.
Like how some murder mystery games are when they use the ghost ability and it makes them invisible for a certain period of time when they are murderer but make it toggle instead.