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

How to get different part names in loop?

Asked by
TechModel 118
2 years ago

the problem is when I am trying this, it doesn't work. I only want the the rest of the body, not head to be invisible. We do a little bit a trolling only head floating... The problem is between v and transparency because I don't know what to put in between to get the loop name so this loop does nothing.

for i, v in pairs(game:GetService("Players"):GetPlayers()) do
            if v ~= LocalPlayer and v:IsA("BasePart") and v.Name ~= "Head" then
                v.Transparency = 1
            end
        end

1 answer

Log in to vote
0
Answered by 2 years ago

I didn't fully understand what you were saying, sorry.

Are you trying to make this show up to all players or only to the LocalPlayer?

If for everybody, this is the code (must be in Server):

for i, v in pairs(game:GetService("Players"):GetPlayers()) do
    local character = v.Character or v.CharacterAdded:Wait()
    if character then
        for x, y in pairs(character:GetChildren()) do
            if y:IsA("BasePart") then
                if y.Name ~= "Head" then
                    return
                else
                    y.Transparency = 1
                end
            end
        end
    end
end

But if for local (yourself) this is the code (must be in Client):

local LocalPlayer = game.Players.LocalPlayer
local char = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
if char then
    for i, v in pairs(char:GetChildren()) do
        if v:IsA("BasePart") then
            if v.Name ~= "Head" then
                return
            else
                v.Transparency = 1
            end
        end
    end
end

But if you want everyone to be invisible but you can only see it, just copy the first one, but put it in a Client script.

Please correct me if there are mistakes. Thanks!

Ad

Answer this question