The title says It all, how can I modify this script so Its more shorter, I don't want to copy and paste line 7 and 9 just to make the player Invisible and visible
Script:
local Troll = script.Parent local Debounce = false Troll.Humanoid:GetPropertyChangedSignal("Health"):Connect(function() if not Debounce then Debounce = true Troll.Torso.Transparency = 1 ----Don't want to literally copy & paste this just to make all the bodyparts Invisible wait(3) Troll.Torso.Transparency = 0 wait(1) Debounce = false end end)
you can use for loops, loop through each body part of the person!
local Troll = script.Parent local Debounce = false Troll.Humanoid:GetPropertyChangedSignal("Health"):Connect(function() if not Debounce then Debounce = true for _, Part in Troll:GetChildren() do if Part:IsA("BasePart") and Part.Name ~= "HumanoidRootPart" then Part.Transparency = 1 end end wait(3) for _, Part in Troll:GetChildren() do if Part:IsA("BasePart") and Part.Name ~= "HumanoidRootPart" then Part.Transparency = 0 end end wait(1) Debounce = false end end)
but this script is too long so i'll create a function for that:
local Troll = script.Parent local Debounce = false local function SetTransparency(Transparency) for _, Part in Troll:GetChildren() do if Part:IsA("BasePart") and Part.Name ~= "HumanoidRootPart" then Part.Transparency = Transparency end end end Troll.Humanoid:GetPropertyChangedSignal("Health"):Connect(function() if not Debounce then Debounce = true SetTransparency(1) wait(3) SetTransparency(0) wait(1) Debounce = false end end)
notice that i ignore HumanoidRootPart
since that should always stay invisible.