Error adding hats to the player

Hello, I’m trying to make a hat that I have stored in replicated storage clone and go onto the player’s head when they join. I tried this and it didn’t seem to work and didn’t give me any errors. I tried searching up how to do this on the dev wiki but I couldn’t find anything, what can I do to fix this?

Script:

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local bvClone = game.ReplicatedStorage.Hats.BlackValk:Clone()
		bvClone.Parent = char
		end)
	end)
1 Like

Just parenting a accessory does not work. You must actually use the built in function or manually weld said accessory.

Here is a link to the API: Humanoid | Roblox Creator Documentation

Here is an example of usage:

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local bvClone = game.ReplicatedStorage.Hats.BlackValk:Clone()
		char.Humanoid:AddAccessory(bvClone)
	end)
end)

Of course said example is just a basic example based on the code you provided.