Attachments not appearing on CharacterAdded

In my game, I am making a trail shop.


When a player equips a trail, if they die the trail will auto equip. One of the most expensive trails(arm rainbow) doesn’t seem to create the attachments to the trail, just the trail itself.

local function equipArmRainbow(player, char)
	
	local arm1 = serverStorage:WaitForChild(player.Name.."'sTrails"):WaitForChild("Arm Rainbow"):Clone()-- cloning the trail
	arm1.Parent = char:WaitForChild("HumanoidRootPart")
			
	local arm2 = arm1:Clone()
	
	arm2.Parent = char:WaitForChild("HumanoidRootPart")
	
	print("Was parented")
	arm2.Name = (arm2.Name .."2")
-------->>>>	Here....
	local at0 = Instance.new("Attachment", char:WaitForChild("LeftUpperArm"))
	at0.Name = ("AttachmentZero")
	local at1 = Instance.new("Attachment", char:WaitForChild("LeftLowerArm"))
	at1.Name = ("Attachment1")
	local at2 = Instance.new("Attachment", char:WaitForChild("RightUpperArm"))
	at2.Name = ("Attachment2")
	local at3 = Instance.new("Attachment", char:WaitForChild("RightLowerArm"))
	at3.Name = ("Attachment3")	
	
	arm1.Attachment0 = at0
	arm1.Attachment1 = at1
	
	arm2.Attachment0 = at2
	arm2.Attachment1 = at3
---------->	To here doesn't run. However, the print statement below does
	print("Equipped the rainbow arm trail")
end

Character Added:

player.CharacterAdded:Connect(function(character)
	print("Ran")
	if currentTrailEquip.Value ~= "None yet" then -- if this value = "None yet", then below wont run
		print("Died, re-equip trail")
		equipTrail(character) -- in this function, it just checks what trail the player was currently equipping. If is the arm rainbow, then it will call the armRainbow function
	end
end)

There’s one error, however it just says that the attachments don’t exist. This is not the full script(just the important parts). Everything is in Server Script Service. Is it a problem with Instance.new?

Have a good day!

1 Like

Few things I have remarked on your code that might be the issue

Alright so first off I have read a few dev forum posts indicating to not use the parent argument in the Instance.new() parentheses.
More can be found in this post: PSA: Don't use Instance.new() with parent argument

Another thing I have remarked is that when making the attachments you are attaching an item from ServerStorage then cloning it again and attaching it to eachother, which does not make sense to me.

What I would suggest is set the attachment to the character’s HumanoidRootPart rather than the other item. Another thing would be that the attachment is not Cloning on the Character’s HumanoidRootPart, so you might want to set the Attachment’s CFrame to the HumanoidRootPart’s.

Sorry for being too vague, I’m not used to explaining things properly.

1 Like

Thanks for replying! I edited the all the Instance.new parts of my script, however it still doesn’t work. I have 2 questions though:

There is a folder with all the players owned trails. I clone them because if the player died while the trail was equipped, there would be no way to get it back, if that makes sense. Do you think I should have attachments already in the trail when its cloned?

I’m a little confused about this. If I attach all the attachments just to the humanoid root part, how could the trail look as though its in the arm?

Yeah sorry I got confused myself when reading your code and wrote strangley. So what I think you can do for that first statement you quoted is instance the attachments since you would want to set the attachment’s CFrame to the character’s HumanoidRootPart and not empty space.
As for the second quote, I mean that when you clone and object in workspace you are not setting it’s position in your code which make the attachment plus the trail in a void area unknown unless you check the position. So maybe do something like attachment.CFrame = HumanoidRootPart.CFrame for each attachments so that the trail goes onto the character and not an empty space.
I don’t know if that would work but try it out.

1 Like

It now respawns! Thank you so much. Although I do have one more question.

This is my current code for an attachment:

local at0 = Instance.new("Attachment")
at0.Name = ("Attachment0")
at0.CFrame = char:WaitForChild("HumanoidRootPart").CFrame + Vector3.new(1,0,0) 
at0.Parent =  char:WaitForChild("HumanoidRootPart")

My question is about the + Vector3.new(1,0,0) part. It doesn’t seem to be right beside the player. In fact, its not even close to the player! What should I change this to?

1 Like

Here is something I would do

local at0 = Instance.new("Attachment")
at0.Name = ("Attachment0")
at0.CFrame = char:WaitForChild("HumanoidRootPart").CFrame * CFrame.new(1,0,0) 
at0.Parent =  char.HumanoidRootPart --No need for WaitForChild()

Since you are doing CFrames you must do your math with CFrames. I mean you could of done Vector3 but I just took CFrame as an example since it’s what I would do.

If you wanted it with Vector3

local at0 = Instance.new("Attachment")
at0.Name = ("Attachment0")
at0.CFrame = char:WaitForChild("HumanoidRootPart").Position + Vector3.new(1,0,0) 
at0.Parent =  char.HumanoidRootPart

Remeber to mark as solution :wink:

1 Like