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

GetChildren not working how I want it to?

Asked by 7 years ago
Edited 7 years ago

I have a function that when I click the teleport button I want it to fade the character away then teleport them, then fade back it, but for some reason it teleports the player, fades each part out and in one by one, i.e. The torso fades out then fades in, then the left arm fades out and in...

player = script.Parent.Parent.Parent

script.Parent.TP1.TextButton.MouseButton1Click:connect(function()
    for _, child in ipairs(player.Character:GetChildren()) do
            if child:IsA("BasePart") then
                child.Transparency = .1
                wait(.1)
                child.Transparency = .2
                wait(.1)
                child.Transparency = .3
                wait(.1)
                child.Transparency = .4
                wait(.1)
                child.Transparency = .5
                wait(.1)
                child.Transparency = .6
                wait(.1)
                child.Transparency = .7
                wait(.1)
                child.Transparency = .8
                wait(.1)
                child.Transparency = .9
                wait(.1)
                child.Transparency = 1
                wait(.1)
                player.Character:MoveTo(game.Workspace.LC2.Position)
                wait(.1)
                child.Transparency = .9
                wait(.1)
                child.Transparency = .8
                wait(.1)
                child.Transparency = .7
                wait(.1)
                child.Transparency = .6
                wait(.1)
                child.Transparency = .5
                wait(.1)
                child.Transparency = .4
                wait(.1)
                child.Transparency = .3
                wait(.1)
                child.Transparency = .2
                wait(.1)
                child.Transparency = .1
                wait(.1)
                child.Transparency = 0
            elseif child:IsA("Model") then
                --N/A
        end
    end
end)
0
elseif child:IsA("Model") then why is this line here ? basically it means nothing Bulvyte 388 — 7y
1
So i dont need that, I left it in there just incase anyone said I needed it. dotProgram 0 — 7y

1 answer

Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
7 years ago

First off, use a for loop. It will drastically shorten your code:

for transparency = 0, 1, 0.1 do
    child.Transparency = transparency
    wait(0.1)
end

The reason only one body part changes at a time is because the loop goes through them one at a time. It's pretty simple to understand. You apply the transparency change to the first item in the list, then the second, then the third -- one at a time.

If transparency is 0.1, then you need to change all of the parts to 0.1. Then you edit transparency and do it all again. Nothing fancy, just logic.

for transparency = 0, 1, 0.01 --makes it smoother with 0.01
    --edit all the parts
    for i, child in ipairs( player.Character:GetChildren() ) do
        if child:IsA("BasePart") then
            child.Transparency = transparency
        end
    end
    --wait, then change transparency
    wait()
end

You can do the same thing in reverse to make it fade back in.


Another tip, since you're working with GUIs you should be using a local script. Therefore, you can use game.Players.LocalPlayer instead of parenting up to it.

0
I did fix my code but it wasen't doesn't look like this. If I end up having any errors Ill use this. dotProgram 0 — 7y
Ad

Answer this question