I want for all players that join, they will have the hat that I put in the id below.
I have tryed other things but cant seem to find the problem..
game.Players.PlayerAdded:connect(function(player)
repeat wait()until player.Character
local hatId=0000000 --Hat ID
if player.Name=="name"then
hatId=0000000 --Hat ID
end
local hat = game:service("InsertService"):LoadAsset(hatId):GetChildren()[1]
hat.Parent=player.Character
end)

2 comments
Looking at your code, it's lines 3 and 5; You did not set a valid Asset ID for the 'InsertService' to add the specific object into the game, also (in my opinion), it is a bad idea to set the Object's Parent property to the Parent right after calling the 'LoadAsset' function of 'InsertService'; The Object may not be existant at the time of execution.
Line 7. game:GetService("InsertService")