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

How do I make a for loop grab all parts at once?

I'm trying to make a script that makes the player disappear when "E" is pressed on the keyboard. The parts are disappearing but at different times. Here's the full script:

local player = game:GetService("Players").LocalPlayer.Character:GetChildren()
local userinput = game:GetService("UserInputService")

userinput.InputBegan:Connect(function(key)
	for i, v in pairs(player) do
		if key.KeyCode == Enum.KeyCode.E then
			for i = 1,10 do
				v.Transparency = v.Transparency + 0.1
				wait(0.001)
			end
		end
	end
end)

By the way, I'm not sure how to get the accessories and face to disappear.

5 comments

0

What do you means? Your script wasn't have any code to make parts dissapear but the part just dissapered..? How...?

0

And it's disaperred at different time (Illuminati song)

0

Even if you'd coded it correctly, I don't see the point of fading out your own character on the client. You realize that all the other players will still see you, right? These changes won't replicate to the server.

0

I don't really need to show it on the other players' screens, but it would be nice to. Could you tell me how to do that?

0

it's been a year. i've found out how to replicate said changes to the server a whileee ago. wow.

2 answers

✓ Accepted answer

Try this:

local player = game:GetService("Players").LocalPlayer.Character:GetDescendants() -- This makes sure you get all the parts
local userinput = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService") -- for smooth effects

userinput.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.E then -- first check what key they press
		for _, instance in pairs(player) do -- then go through the character
			if instance:IsA("BasePart") or instance:IsA("Decal") then -- then check if it's a part or a decal
				TweenService:Create(instance, TweenInfo.new(1), {Transparency = 1}):Play() -- Then tween and make smooth transitions
			end
		end
	end
end)

This is because you've set the code to only focus on one part.

For accessories, you can check if they exist in the character, then make their handle invisible.

For face, the face is inside the Head, so Head.face.Transparency.

2 comments

0

Thank you! I would upvote if I was able to.

0

Also, I tried to check if v was an accessory and then get the handle, but it didn't work.

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