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

How do I make every hat in a player transparent?

Asked by 6 years ago

I made a script that turns the player completely transparent, the only problem is I can't make the players hats transparent. How would I make every hat in the player transparent?

Code (Local script):

local plr = game.Players.LocalPlayer

function onKeyPress(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.Z then

            plr.Character.Head.Transparency = 1
            plr.Character.Torso.Transparency = 1
            plr.Character["Right Arm"].Transparency = 1
            plr.Character["Left Arm"].Transparency = 1
            plr.Character["Right Leg"].Transparency = 1
            plr.Character["Left Leg"].Transparency = 1



    end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)

1 answer

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

See, the issue with changing transparency this way is that you don't know the hat's name. That means you'd have to loop through items to see if they're a hat. But then you could just include the parts in the loop. Here's how I'd do it:

--This will not work for FE games, or would only show him his own body as transparent
local plr = game.Players.LocalPlayer
local debounce = true
function onKeyPress(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.Z and debounce then
            debounce = false
            for a,part in pairs (plr.Character:GetChildren()) do
                if part.ClassName == "Part" then -- their torso,head,legs and arms
                    part.Transparency = 1
                elseif part.ClassName == "Accessory" then
                    part.Handle.Transparency = 1-- this should make all hats transparent now
                end
            end
            wait(1)
            debounce = true


    end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)
0
It makes the body transparent but it doesn't delete the hats, so I changed Destroy to Remove and that didn't work either. I also checked if my game as on FE and its not. roblox99456789 104 — 6y
1
Alright, I'll edit my answer to make it change the hat to transparent instead of destroy. iamnoamesa 674 — 6y
0
Thanks! Works like a charm! roblox99456789 104 — 6y
Ad

Answer this question