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

GetChildren not working how I want it to?

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)

2 comments

0

elseif child:IsA("Model") then why is this line here ? basically it means nothing

1

So i dont need that, I left it in there just incase anyone said I needed it.

1 answer

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.

1 comment

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.

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