My Trail is not being attached

I was trying to make it that when an even is called a trail is attached to the player but it does not work can anyone help?

local AttachTrail = game.ReplicatedStorage:WaitForChild("AttachTrailEvent")

AttachTrail.OnServerEvent:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local trail = game.ReplicatedStorage.Peach:Clone()
		trail.Parent = char.Head

		local attachment0 = Instance.new("Attachment",char.Head)
		attachment0.Name = "TrailAttachment0"
		
		local attachment1 = Instance.new("Attachment",char.HumanoidRootPart)
		attachment1.Name = "TrailAttachment1"
		trail.Attachment0 = attachment0
		trail.Attachment1 = attachment1
	end)
end)

You probably want to attach the trail to the current character, not the characters that the player will have in future. So instead of making a CharacterAdded connection, just get the current character by writing player.Character. It’s also more efficient to set parent after setting other properties.

local AttachTrail = game.ReplicatedStorage:WaitForChild("AttachTrailEvent")

AttachTrail.OnServerEvent:Connect(function(player)
	local char = player.Character
	
	local trail = game.ReplicatedStorage.Peach:Clone()

	local attachment0 = Instance.new("Attachment")
	attachment0.Name = "TrailAttachment0"
	attachment0.Parent = char.Head
	
	local attachment1 = Instance.new("Attachment")
	attachment1.Name = "TrailAttachment1"
	attachment1.Parent = char.HumanoidRootPart
	
	trail.Attachment0 = attachment0
	trail.Attachment1 = attachment1
	trail.Parent = char.Head
end)
1 Like