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

Invisible Body script not working??

Asked by 8 years ago

So basically I've been trying to make a FireBody script which makes your body transparent and then you have the particle emitter on your torso and you move around and after about 5 seconds your body turns to normal... So this is what I scripted the problem I am having with it is that it makes the Head transparent and the rest of the body is not transparent and then when you spam the function it would make the torso transparent and then all of a sudden the whole body but the head would be transparent and it's confusing the heck outta me! I just don't even know what is going on at the moment.... Anyways here is the code:

player = game.Players.LocalPlayer
mouse = player:GetMouse()

mouse.KeyDown:connect(function(key)
    if key == "q" then
    local char = player.Character
    local hum = char:WaitForChild("Humanoid")
    hum.WalkSpeed = hum.WalkSpeed +90
    local children = char:GetChildren()
    for i = 1, #children do
        wait()
        for i,v in pairs(children) do
            if v.ClassName == "Hat" then
                v.Handle.Transparency = 1
            elseif v:IsA("BasePart") then
                v.Transparency = 1
                for _, s in pairs(v:GetChildren()) do
                    if s:IsA("Decal") then
                        s.Transparency = 1
               wait(5)
                   hum.WalkSpeed = hum.WalkSpeed -90
                   if v.ClassName == "Hat" then
                      v.Handle.Transparency = 0
                elseif v:IsA("BasePart") then
                      v.Transparency = 0
                 for _, s in pairs(v:GetChildren()) do
                     if s:IsA("Decal") then
                        s.Transparency = 1
                            end
                         end
                         end
                      end
                   end    
                end
            end
        end
    end
end)

Thank you, I hope you can tell me what is wrong here this is confusing me really!

1 answer

Log in to vote
1
Answered by 8 years ago

The problem is that you're not ending the if then statements at the right time. Here's what you need to do:

for i,v in pairs(children) do
if v:IsA("Hat") then
v.Handle.Transparency = 1
elseif v:IsA("Part") then
v.Transparency = 1
for i,vc in pairs(v:GetChildren()) do
if vc:IsA("Decal") then
vc.Transparency = 1
end -- Ends the if statement for the Decal.
end -- Ends the loop for the parts children.
end -- Ends the if statement.
end -- Ends the loop.
wait(5)
for i,v in pairs(children) do -- Starts a second loop to reverse the transparency.
if v:IsA("Hat") then
v.Handle.Transparency = 0
elseif v:IsA("Part") then
v.Transparency = 0
for i,vc in pairs(v:GetChildren()) do
if vc:IsA("Decal") then
vc.Transparency = 0
end -- Ends the second  if statement for the Decal.
end -- Ends the second  loop for the parts children.
end -- Ends the if statement.
end -- Ends the second loop.

Also, a trick I normally do to make it easier to read multiple loops, if statements, etc is adding a line so I know where the script ends.

0
Thank you! KingLoneCat 2642 — 8y
Ad

Answer this question