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

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

Asked by 4 years 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 = 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!

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? User#834 0 — 4y
0
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 — 4y
0
Thanks guys, I'll try this out! PadmeOragana 78 — 4y
0
Hi, I tried the "game.Players.LocalPlayer" but it didn't work, the hat didn't even show. PadmeOragana 78 — 4y

Answer this question