✓ Accepted answer
You need to set the position of the hat. You cannot just assign its parent to Character without giving it any info on where its going to go.
local playerModel = game.Players.LocalPlayer
local Character = workspace:FindFirstChild(playerModel.Name)
script.Parent.MouseButton1Click:Connect(function()
if Character:FindFirstChild("Humanoid") then
local h = Instance.new("Hat")
local p = Instance.new("Part")
h.Name = "Hat"
p.Parent = h
p.Position = hit.Parent:findFirstChild("Head").Position
p.Name = "Handle"
p.formFactor = 0
p.Size = Vector3.new(1, 0.4, 1)
p.BottomSurface = 0
p.TopSurface = 0
p.Locked = true
game.ServerStorage.BlackHair:Clone().Parent = Character
h.Parent = Character
h.AttachmentForward = Vector3.new (-0, -0, -1)
h.AttachmentPos = Vector3.new(0, 0.4, 0)
h.AttachmentRight = Vector3.new (1, 0, 0)
h.AttachmentUp = Vector3.new (0, 1, 0)
wait(5)
end
end)
My code may not all be correct but I hope you understand that you'll need to give it coordinates.
3 comments
Would "Hat" Be considered Accessory now? Or would "hat" Still function?
Accessory
I get an error that says "attempt to index field "parent" (a nil value)" Line 12