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 every hat in a player transparent?

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

✓ Accepted answer

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)

3 comments

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.

1

Alright, I'll edit my answer to make it change the hat to transparent instead of destroy.

0

Thanks! Works like a charm!

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