This script works 100% fine. But the thing is when I try and make the hats on the local player this tool is inside of, it only makes 1 of there hats transparency = 1. I am wanting to make all of the hats they have transparency = 1.
This is my script: [Line 22-24] & [Line 36-38]
local mouse = game.Players.LocalPlayer:GetMouse() function Light() local player = game.Players.LocalPlayer local playerChar = player.Character local playerLight = playerChar.Torso:FindFirstChild("Light") if playerLight then playerLight:Destroy() else local humanoid = playerChar:findFirstChild("Humanoid") if humanoid == nil then return end playerChar:findFirstChild("Head").Transparency = 0.98 playerChar:findFirstChild("Torso").Transparency = 0.98 playerChar:findFirstChild("Left Arm").Transparency = 0.98 playerChar:findFirstChild("Right Arm").Transparency = 0.98 playerChar:findFirstChild("Left Leg").Transparency = 0.98 playerChar:findFirstChild("Right Leg").Transparency = 0.98 playerChar:findFirstChild("Head"):findFirstChild("face").Transparency = 1 for i, d in pairs (playerChar:GetChildren()) do if d.className == "Hat" then d.Handle.Transparency = 1 wait(10) playerChar:findFirstChild("Head").Transparency = 0 playerChar:findFirstChild("Torso").Transparency = 0 playerChar:findFirstChild("Left Arm").Transparency = 0 playerChar:findFirstChild("Right Arm").Transparency = 0 playerChar:findFirstChild("Left Leg").Transparency = 0 playerChar:findFirstChild("Right Leg").Transparency = 0 playerChar:findFirstChild("Head"):findFirstChild("face").Transparency = 0 for i, d in pairs (playerChar:GetChildren()) do if d.className == "Hat" then d.Handle.Transparency = 0 script.LocalScript.Disabled = true wait(0.000005) player.PlayerGui.InvisibleAbility:Destroy() script:Destroy() end end end end end end mouse.KeyDown:connect(function(key) key = key:lower() if key == "e" then Light() end end)
You should start by cleaning that code up a little. The indentation is very messy and there are a few things you could replace with short functions and for loops. Try studying this code:
-- I apologize if there are any typos, i didn't run this in studio before submitting it. local player = game:GetService("Players").LocalPlayer local char = player.Character or player.CharacterAdded:wait() local mouse = player:GetMouse() local function VisiblePlayer(char, trans) for i,v in pairs (char:GetChildren()) do if v:IsA'BasePart' then v.Transparency = trans if v.Name=="Head" then local f = v:FindFirstChild("face") if f then f.Transparency = trans end end elseif v:IsA'Hat' then local h = v:FindFirstChild("Handle") if h then h.Transparency = trans end end end end local function Light() local light local torso = char:FindFirstChild("Torso") if torso then light = torso:FindFirstChild("Light") end if light then light:Destroy() else VisiblePlayer(char, 1) wait(10) VisiblePlayer(char, 0) end end mouse.KeyDown:connect(function(key) if key:lower()=="e" then Light() end end)
Hope this helped. This is just based off what i can understand of your code.