I just need a GUI that removes a hat from a morph!

This is one big thread with interesting replies. When that is said, here is your solution:

--Localscript:
local HatRemote = game:GetService("ReplicatedStorage"):WaitForChild("HatRemote")
local HatButton = script.Parent:WaitForChild("HatButton")
local Debounce = false
HatButton.Activated:Connect(function()
	if Debounce then return end
	Debounce = true
	HatRemote:FireServer()
	task.wait(0.5)
	Debounce = false
end)
--Serverscript
local HatRemote = game.ReplicatedStorage.HatRemote
local Debounce = {}
HatRemote.OnServerEvent:Connect(function(Player)
	if Debounce[Player.Name] then return end
	Debounce[Player.Name] = true
	local Character = Player.Character
	if Character then
		for _, Accessory in pairs(Character:GetChildren()) do
			if Accessory:IsA("Accessory") and Accessory.AccessoryType == Enum.AccessoryType.Hat then
				local Handle = Accessory:FindFirstChild("Handle")
				if Handle then
					if Handle.Transparency == 0 then
						Handle.Transparency = 1
					else
						Handle.Transparency = 0
					end
				end
			end
		end
	end
	task.wait(0.5)
	Debounce[Player.Name] = nil
end)

Setup:
image

somehow this ended up making the morph’s hat itself dissapear… meaning the player morphs as a silly guy under the mask, plus the function kinda works when you click it back, the helmet returns, and if clicked again, it’s the opposite, something like a loop thing…

lemme just mention that my morph is “click torso to become this person” thing, so I think it’s because of that.

Scripting support is for programmers to communicate on issues in code, we don’t help if there is no script to start with…

1 Like

@GrizzlyDude27, try using my script, maybe, it’ll work.

Look at these line in my script:

		for _, Accessory in pairs(Character:GetChildren()) do
			if Accessory:IsA("Accessory") and Accessory.AccessoryType == Enum.AccessoryType.Hat then

We go through all “Children objects” in the morph/character. Then we check if that “child object”(referred to as Accessory in this case, just know that all children are not accessories, we could’ve have called it anything, even Banana)
If that “child object” is a “Accessory” and that "child object"s AccessoryType is equal to “Hat” then we turn it visible/invisible.
What you have to do, is some way specify which hat you want to dissapear. You can do this by adding another statement like this:

		for _, Accessory in pairs(Character:GetChildren()) do
			if Accessory:IsA("Accessory") and Accessory.AccessoryType == Enum.AccessoryType.Hat and Accessory.Name == "DarthVaderMask" then

well I do want it to reappear again and dissapear again per click on the accessory.