Humanoid documentation includes a function "AddAccessory" to do just that!
An example would be this:
if workspace:FindFirstChild("Pumpkin") then
game.Players.PlayerAdded:Connect(function(player)
if player.Character then
local accessory = workspace.Pumpkin
player.Character:WaitForChild("Humanoid"):AddAccessory(accessory)
end
end)
end
or optionally you could do this:
if workspace:FindFirstChild("Pumpkin") then
game.Players.PlayerAdded:Connect(function(player)
local result,err = pcall(function()
local accessory = workspace.Pumpkin
player.Character:WaitForChild("Humanoid"):AddAccessory(accessory)
end)
if not result then
warn(err)
end
end)
end