Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Invisible Body script not working??

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

✓ Accepted answer

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.

1 comment

0

Thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.