I'm trying to make a Surface GUI button which makes the player wear a hat when it is clicked. Here's what I've tried so far -
script.Parent.MouseButton1Click:connect(function() debounce = true function onClicked(plr) if debounce == true then debounce = false local h = Instance.new("Hat") local p = Instance.new("Part") h.Name = "Hat" p.Parent = h p.Position = plr.Character:findFirstChild("Head").Position p.Name = "Handle" p.formFactor = 0 p.Size = Vector3.new(2, 1, 1) p.BottomSurface = 0 p.TopSurface = 0 p.Locked = true script.Parent.Mesh:clone().Parent = p h.Parent = plr.Character h.AttachmentPos = Vector3.new(0,.8, 0) wait(5) debounce = true end end end) script.Parent.ClickEvent.OnServerEvent:connect(onClicked)
Anyone know how to fix this?