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

How do you make a players accessories invisible on click?

Asked by 5 years ago
Edited 5 years ago

I'm wondering how to make a players accessories invisible on click.

I'm helping a friend code a tank into Roblox but I ran into a slight inconvenience.

I know how to make a players Torso, Left Arm, Left Leg, Right Arm, Right Leg and Head invisible but I'm not quite sure not to make a players accessories invisible.

This is what I have so far:

Tank.MeshPart1.ClickDetector.MouseClick:Connect(function(Click)

    local Character = game.Players.LocalPlayer.Character

    if InTank == false then

        game.Players.LocalPlayer.Character.Torso.Transparency = 1

        game.Players.LocalPlayer.Character["Left Arm"].Transparency = 1

        game.Players.LocalPlayer.Character["Left Leg"].Transparency = 1

        game.Players.LocalPlayer.Character["Right Arm"].Transparency = 1

        game.Players.LocalPlayer.Character["Right Leg"].Transparency = 1

        game.Players.LocalPlayer.Character.Head.Transparency = 1

        game.Players.LocalPlayer.Character.HumanoidRootPart.Transparency = 1






        InTank = true

    end

end)

It works but I still need to get rid of the players accessories.

I looked everywhere to find an answer but I just couldn't find one.

If anyone knows how to do this, please help.

1 answer

Log in to vote
0
Answered by
Elixcore 1337 Moderation Voter
5 years ago
Edited 5 years ago

It is simpler to run a generic for loop on the character's descendants, this way you can obtain all of the parts and change their transparency.

local ts = {}



Tank.MeshPart1.ClickDetector.MouseClick:Connect(function(Click)

    local Character = game.Players.LocalPlayer.Character

    if not InTank then

    for i,v in next, Character:GetDescendants() do
        if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then
            ts[v.Name] = v.Transparency
            v.Transparency = 1
        end
    end

        InTank = true

    end

end)

Since we added all the parts' transparencies to a dictionary, we can now also undo the Transparency, like this:

for i,v in next, Character:GetDescendants() do
    if ts[v.Name] then
        v.Transparency = ts[v.Name]
    end
end
Ad

Answer this question