Unable to cast value to Object | How can I attach a multiple-part accessory?

Hey,

I’m trying to attach a helmet to the player’s character with a multiple-part hat accessory.

The error:
image
Line 120:
Player.Character.Humanoid:AddAccessory(Helmet)
Line 217:
attachHelmet(Player, "EMSCommanderHelmet")

How would I be able to do this? I tried the following:

The function:

local function attachHelmet(Player, Helmet)
	if Helmet ~= "NoHelmet" then
		local helmetToAttach = ServerStorage.Helmets:FindFirstChild(Helmet)
		for i = 1, #helmetToAttach:GetChildren() do
			if helmetToAttach:GetChildren()[i] ~= helmetToAttach.Center then
				local Weld = Instance.new("WeldConstraint")
				Weld.Part0 = helmetToAttach:GetChildren()[i]
				Weld.Part1 = helmetToAttach.Center
				Weld.Parent = helmetToAttach.Center

				helmetToAttach:GetChildren()[i].Anchored = false
			end
		end
		Player.Character.Humanoid:AddAccessory(Helmet)
	elseif Helmet == "NoHelmet" then
		--delete helmet
	end
end

I tried welding the accessory together, to obtain the result, but it sadly didn’t work.
This is how explorer looks like:
image

Any one have an idea? Thanks!

Replace Helmet with helmetToAttach

1 Like

if you want that as soon as the player enters the game this happens you can use this:
image
inside the HumanoidDescription you will configure and put the helmet id!

then just create a script in ServerScriptService and copy what is below!

workspace.Baseplate.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent:FindFirstChild("Humanoid"):ApplyDescription(game.ServerStorage.HumanoidDescription)
	end
end)

1 Like

Im not sure how the accessories works, but I think you need a Handle part (Just a part named Handle), to make the accessory work.

1 Like

Would that support multiple-parts though? Doubt it would work if I’d add the rest of the model in the Handle part.

To Attach an accessory to a player easily and properly you will need to convert your accessory to a proper accessory instance. Most accessory’s are not multiple parts but if there are multiple parts just weld them together. To add the accessory onto the player just use

Humanoid:AddAccessory(Your_Accessory)
1 Like