Hi there, I am still working on a player customizer GUI, and I made a hat GUI for it. Well, it was all working perfectly until I can't remember what happened. It does work, yes, but not how I want it. You see, when you press a button, the hat goes on the player, but then disappears. Here's the script:

Player = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent
Human = Player.Character

debounce = true

function onClicked(mouse)

if debounce == true then
	debounce = false
	Hat = Instance.new("Accessory")
	Handle = Instance.new("Part")
	Hat.Name = "Hatino"
	Handle.Name = "Handle"
	Handle.Parent = Hat
	Handle.Position = Human:findFirstChild("Head").Position
	Handle.formFactor = 0
	Handle.Size = Vector3.new(1,1,1)
	Handle.TopSurface = 0	
	Handle.Locked = true
	script.Parent.Mesh:clone().Parent = Handle
	Hat.Parent = Human
	Hat.AttachmentForward = script.Parent.AttachmentForward.Value
	Hat.AttachmentPos = script.Parent.AttachmentPos.Value
	Hat.AttachmentRight = script.Parent.AttachmentRight.Value
	Hat.AttachmentUp = script.Parent.AttachmentUp.Value
	wait(1)
	debounce = true
end

end
script.Parent.MouseButton1Click:connect(onClicked)

Keep in mind that it is in StarterGUI and that it does work but disappears the next second. It's also in a normal script, not local, but I tried making it in local and had the same outcome.

Thank you!

4 comments

0

First want to mention that the script.Parent.Parent..... can easily be replaced with game.Players.LocalPlayer if you're using a Localscript, however can you try Humanoid:AddAccessory instead of setting the attachment manually?

0

Instead of parenting the hat to human, try parenting the hat to "humanoid"

Oh. And you need to have a game:getservice("Players")

0

Thanks guys, I'll try this out!

0

Hi, I tried the "game.Players.LocalPlayer" but it didn't work, the hat didn't even show.