Motor6D doesn't appear when I Instance.new() it

  1. I want to attach a tool to the player’s right hand when the player equips it.

2.Whenever I try to Instance.new() a Motor6D to the player’s right hand, a weld shows up instead of a Motor6D

3.I double checked the script and there are no errors in the output

Here is the code

local tool = script.Parent

tool.Equipped:Connect(function(plr)
	local char = plr.CharacterAdded:Wait()
	char.RightHand:WaitForChild("RightGrip"):Destroy()
	local M6D = Instance.new("Motor6D",char.RightHand)
	M6D.Name = "AxeM6D"
	M6D.Part0 =  char.RightHand
	M6D.Part1 = tool.Handle
end)

tool.Unequipped:Connect(function(plr)
	local char = plr.CharacterAdded:Wait()
	if char.Righthand:FindFirstChild("AxeM6D") then
		char.RightHand.AxeM6D:Destroy()
	end
end)

Thanks in Advance!
:smiley:

Char = plr.Character
If not plr.Character then
Char = plr.CharacterAdded:Wait()
else

I am trying it right now.

[30charr]

No Luck, it still adds a weld instead of Motor6D.

Print out its full name, Motor6D:GetFullName()
Motor6D’s are a type of weld so like…

When I try to print it, it prints out nothing.

Print the motor6d’s parent and thats parent.
I don’t think that the motor6d exists

It prints out the name of the folder and “ReplicatedStorage”

@TheBrainy06

First of all, when a tool is Equipped the mouse is passed as an arguement, not the player object. So you shouldn’t get the Character like that instead you could do this

local char = script.Parent.Parent 

then, when a tool is Unequipped it is put back in the Backpack, where you can’t get Player unless, you have defined it in a variable before. What I did is a simple fix for it and rewrote the script like this:

local tool = script.Parent
local Player

tool.Equipped:Connect(function()
	script.Parent.Parent["RightHand"]:WaitForChild("RightGrip"):Destroy()
	Player = script.Parent.Parent.Name
	local M6D = Instance.new("Motor6D", script.Parent.Parent["RightHand"])
	M6D.Name = "AxeM6D"
	M6D.Part0 = script.Parent.Parent["RightHand"]
	M6D.Part1 = tool.Handle
end)

tool.Unequipped:Connect(function()
	if game.Players[Player].Character["RightHand"]:FindFirstChild("AxeM6D") then
		game.Players[Player].Character["RightHand"].AxeM6D:Destroy()
	end
	Player = nil
end)	
4 Likes

Thank you so much, this solution worked.