Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how to make For loop for Invisibility power up?

Asked by
Fad99 286 Moderation Voter
5 years ago

Ok So i have an invisible power up but its not fully functional yet i want to have a for look look through the character to make every thing that can be Transparent = 100 to do so, Can someone help me simplify my code and learn to do a for loop like this? The current code i have cant make clothing or accessory invis

Here's my code :

local dad = script.Parent


local function Invis(part)

local p = part.Parent

if game.Players:GetPlayerFromCharacter(p)then

    p.LeftFoot.Transparency = 100
    p.LeftLowerLeg.Transparency = 100
    p.LeftUpperLeg.Transparency = 100
    p.LeftUpperArm.Transparency = 100
    p.LeftLowerArm.Transparency = 100
    p.LeftHand.Transparency = 100
    p.RightHand.Transparency = 100
    p.RightLowerLeg.Transparency = 100
    p.RightFoot.Transparency = 100
    p.RightUpperArm.Transparency = 100
    p.RightLowerArm.Transparency = 100
    p.RightUpperLeg.Transparency = 100
    p.LowerTorso.Transparency = 100
    p.UpperTorso.Transparency = 100
    p.Head.Transparency = 100
    p.Head.face.Transparency = 100

    dad:Destroy()
    wait(10)

    p.LeftFoot.Transparency = 0
    p.LeftLowerLeg.Transparency = 0
    p.LeftUpperLeg.Transparency = 0
    p.LeftUpperArm.Transparency = 0
    p.LeftLowerArm.Transparency = 0
    p.LeftHand.Transparency = 0
    p.RightHand.Transparency = 0
    p.RightLowerLeg.Transparency = 0
    p.RightFoot.Transparency = 0
    p.RightUpperArm.Transparency = 0
    p.RightLowerArm.Transparency = 0
    p.RightUpperLeg.Transparency = 0
    p.LowerTorso.Transparency = 0
    p.UpperTorso.Transparency = 0
    p.Head.Transparency = 0
    p.Head.face.Transparency = 0

    end

end 

dad.Touched:Connect(Invis)



for doodoo =0 , 10 do

wait(1)

if doodoo == 10 then

    dad:Destroy()

    end

end

1 answer

Log in to vote
0
Answered by
Divistern 127
5 years ago

In this kind of situation you need to loop through the body parts and check the part's Class the 2 Known classes that have the property Transparency are

1-MeshParts 2-Parts

We will have to use the for loop in maintaining the body parts and it can be implemented in the following code as i'll explain in big chunks of code;

Grabbing the user's Data/ Variables:

repeat wait() until game.Players:FindFirstChild("Divistern")
local player = game.Players.Divistern
repeat wait() until player.Character ~= nil
local char = player.Character
local perInvis = 10

Making the "Briefcase" for the player:

--Making a "briefcase"
local playerBriefCase = Instance.new("Folder", game.ReplicatedStorage)
playerBriefCase.Name = player.Name

Looping through body Parts and making them invisible:

for i,v in pairs(char:GetChildren()) do
    if v:IsA("Part") then --Making any "Part" invisible such as the "head"
        v.Transparency = 1
    end
    if v:IsA("MeshPart") then --If the user is using any kind of a roblox package
        v.Transparency = 1
    end
    if v:IsA("Accessory") then --If the user has any hats or accessories
        v.Parent = playerBriefCase
    end
    for i,x in pairs(char.Head:GetChildren()) do --To hide the face of the player
        if x:IsA("Decal") then
            if x.Name == "face" then
                x.Parent = playerBriefCase --Parenting the face in the player's "Briefcase"
            end
        end
    end
end

Delaying:

wait(perInvis)   --Delay between powers

Making Body Parts Visible and retrieving the accessories:

for _,Folder in pairs(game.ReplicatedStorage:GetChildren()) do --Getting the user's private folder
    if Folder.Name == player.Name then
        local briefCase = Folder
        for _,child in pairs(briefCase:GetChildren()) do --Retrieving the user's items
            if child:IsA("Decal") then
                if child.Name == "face" then
                    child.Parent = char.Head
                end
            end
            if child:IsA("Accessory") then
                child.Parent = char
            end
        end
    end
end
for i,v in pairs(char:GetChildren()) do --Making user's body parts visible
    if v:IsA("Part") then
        if v.Name ~= "HumanoidRootPart" then
            v.Transparency = 0
        end
    end
    if v:IsA("MeshPart") then
        v.Transparency = 0
    end
end

Full Overview:

  • Getting Variables

    • Getting Player then Getting Character
    • Adding a variable for the time between invis/vis
    • Making a "BriefCase" for the user to store his/her accessories
  • Looping through the body parts

    • Making Body parts under the class Part Invisible
    • Making Body parts under the class MeshParts invisible
    • Parenting the player's accessories into his "BriefCase"
    • Looping through the Head's Children
      • Getting the player's Face
      • Parenting the player's Face to his/her "BriefCase"
    • Waiting 10 Seconds
  • Finding the user's "BriefCase" in ReplicatedStorage

    • Found the user's "BriefCase"
      • Grabbing the BriefCase's Children From a for loop
      • Checking if the ClassName of objects in the folder are Decals or Accessories
      • If the Object is a Decal then parent it to the user's Head which is in the user's Character
      • If the object is a Accessory then parent it to the user's Character
  • Looping through the user's Character

    • Checking if the object or body part is a Part or a MeshPart
      • if the BodyPart is a Part then making it Visible by setting the transparency to 0
      • if the BodyPart is a MeshPart then making it Visible by setting the transparency to 0

Hope this helped. Sorry for any mistakes if there are, i was writing these while being sick.

0
Thanks! Fad99 286 — 5y
Ad

Answer this question