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

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

Asked by
sngnn 274 Moderation Voter
4 years ago
Edited 4 years ago

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.

0
What do you means? Your script wasn't have any code to make parts dissapear but the part just dissapered..? How...? Xapelize 2658 — 4y
0
And it's disaperred at different time (Illuminati song) Xapelize 2658 — 4y
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. EmilyBendsSpace 1025 — 4y
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? sngnn 274 — 4y
0
it's been a year. i've found out how to replicate said changes to the server a whileee ago. wow. sngnn 274 — 3y

2 answers

Log in to vote
0
Answered by 4 years ago

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)
Ad
Log in to vote
0
Answered by
Qariter 110
4 years ago

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.

0
Thank you! I would upvote if I was able to. sngnn 274 — 4y
0
Also, I tried to check if v was an accessory and then get the handle, but it didn't work. sngnn 274 — 4y

Answer this question