Still have questions? Join our Discord server and get real time help.
Log in to vote

Why won't hat button in GUI make hat stay on player?

Asked by 6 months ago

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 ="Accessory")
    Handle ="Part")
    Hat.Name = "Hatino"
    Handle.Name = "Handle"
    Handle.Parent = Hat
    Handle.Position = Human:findFirstChild("Head").Position
    Handle.formFactor = 0
    Handle.Size =,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
    debounce = true


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!

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? FloweryMonkeyboy5 1089 — 6mo
Instead of parenting the hat to human, try parenting the hat to "humanoid" Oh. And you need to have a game:getservice("Players") ffancyaxax12 181 — 6mo
Thanks guys, I'll try this out! PadmeOragana 41 — 6mo
Hi, I tried the "game.Players.LocalPlayer" but it didn't work, the hat didn't even show. PadmeOragana 41 — 6mo

Answer this question