Mesh doesn't properly attach to player when using script to add

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to add a weight painted and already animated meshes to a custom mesh the player will use.

  2. What is the issue? Include screenshots / videos if possible!
    When the mesh is already attached to the starter character upon launching a test, it sits on the mesh and animates with it just fine. However, when I attempt to attach it via a script, it doesn’t attach to the model nor animate even though the workspace folder reflects that it is parented properly.


  3. What solutions have you tried so far? Did you look for solutions on the Creator Hub?
    So far I have looked into using rigid constraints, however, that does not work with the motor6D rig I have imported from blender and I would rather not have to attempt making and then weight painting the rig again in roblox studio, which I don’t even think is possible.

If this is not a scripting support thing, please let me know and I’ll head over to art design support.

note: the bindable event just updates the player’s inventory gui to show that they have the accessory equipped

local function onClicked(player, accessoryName)
	
	-- detect if the player has the accessory already or not
	
	local hasAccessory = false
	local accessoriesFolder = player.Character:WaitForChild("Accessories")
	for _, accessory in accessoriesFolder:GetChildren() do
		if accessory.Name == accessoryName then
			hasAccessory = true
			print("Player already has accessory equipped.")
		end
	end
	if hasAccessory then
		return
	end
	
	--If the player does not have the accessory, proceede
	-- fire the event to the server to update the player's accessory data
	local beEquipAccesory : BindableEvent = game.ReplicatedStorage.BindableEvents.Server_Server.EquipAccessory
	beEquipAccesory:Fire(player, accessoryName)

	-- create a copy of the accessory and attach it to the player
	local clone = game.ReplicatedStorage.Accessories:FindFirstChild(accessoryName):Clone()
	local playerModel = game.Workspace:WaitForChild(player.Name)
	local humanoid = playerModel:WaitForChild("Humanoid")
	clone.Parent = accessoriesFolder
end

for _, accessory in workspace.AccessoryFolder:GetChildren() do
	accessory.ClickDetector.MouseClick:Connect(function(player)
		onClicked(player, accessory.Name)
	end)
end

I ended up getting help elsewhere. Turns out I needed to manually add the part0 and part1 of the motor6d again.

local function onClicked(player, accessoryName)
	
	-- detect if the player has the accessory already or not
	
	local hasAccessory = false
	local accessoriesFolder = player.Character:WaitForChild("Accessories")
	for _, accessory in accessoriesFolder:GetChildren() do
		if accessory.Name == accessoryName then
			hasAccessory = true
			print("Player already has accessory equipped.")
		end
	end
	if hasAccessory then
		return
	end
	
	--If the player does not have the accessory, proceede
	-- fire the event to the server to update the player's accessory data
	local beEquipAccesory : BindableEvent = game.ReplicatedStorage.BindableEvents.Server_Server.EquipAccessory
	beEquipAccesory:Fire(player, accessoryName)

	-- create a copy of the accessory and attach it to the player
	local clone = game.ReplicatedStorage.Accessories:FindFirstChild(accessoryName):Clone()
	local playerModel = game.Workspace:WaitForChild(player.Name)
	local humanoid = playerModel:WaitForChild("Humanoid")
	clone.Parent = accessoriesFolder
	clone:WaitForChild("IbexHornsMotor6D").Part0 = playerModel:WaitForChild("RootPart")
	clone:WaitForChild("IbexHornsMotor6D").Part1 = clone
	clone.Massless = true
end

for _, accessory in workspace.AccessoryFolder:GetChildren() do
	accessory.ClickDetector.MouseClick:Connect(function(player)
		onClicked(player, accessory.Name)
	end)
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.