Connecting Motot6D via script issue

I am trying to connect two parts with Motot6Ds for animation purposes and it doesnt work.

Here are my scripts:

-- Local script inside of the tool
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Connect6DRE = ReplicatedStorage:WaitForChild("Connect6D")
local Disconnect6DRE = ReplicatedStorage:WaitForChild("Disconnect6D")

local Tool = script.Parent

Tool.Equipped:Connect(function(Tool)
	Connect6DRE:FireServer()
end)

Tool.Unequipped:Connect(function(Tool)
	Disconnect6DRE:FireServer()
end)
-- Server script inside of ServerScriptService
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Connect6DRE = ReplicatedStorage:WaitForChild("Connect6D")
local Disconnect6DRE = ReplicatedStorage:WaitForChild("Disconnect6D")

local ToolName = "M1911A1"

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
		
		local BodyAttach = Instance.new("Motor6D")
		BodyAttach.Name = "BodyAttach"
		BodyAttach.Parent = HumanoidRootPart
	end)
end)


Connect6DRE.OnServerEvent:Connect(function(Player, Tool)
	local Character = Player.Character or Player.CharacterAdded:Wait()
	local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
	local ToolHandle = Tool:WaitForChild("Handle") -- Saying the tool doesn't exist when it does
	local BodyAttach = HumanoidRootPart:WaitForChild("BodyAttach")
	
	BodyAttach.Part0 = HumanoidRootPart
	BodyAttach.Part1 = ToolHandle
end)

Disconnect6DRE.OnServerEvent:Connect(function(Player, Tool)
	local Character = Player.Character or Player.CharacterAdded:Wait()
	local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
	local ToolHandle = Tool:WaitForChild("Handle")
	local BodyAttach = HumanoidRootPart:WaitForChild("BodyAttach")

	BodyAttach.Part0 = HumanoidRootPart
	BodyAttach.Part1 = nil
end)

Error: ServerScriptService.Motor6DServer:21: attempt to index nil with 'WaitForChild'

Connect6DRE expects you pass in a Tool to connect to the Motor6D, you pass in nothing in the FireServer, same applies for Disconnect6DRE

1 Like

Ok I realise what I did now, I passed the Tool in the function when i thought that was the remote event. I wasnt paying attention lol.

1 Like

I am still getting the same error for some reason, I have no idea why.

Edit: Ok I fixed it but now I am getting an error saying Unable to cast value to object on the :LoadAnimation part of the script.

Actually I will create another topic.

The only reason it could is that when you pass in Tool, because you put Tool in the brackets in the Equipped and Unequipped events, it tries to pass in the first return of those events, which is the palyer’s mouse, which will nil if you pass it to the server, just remove the Tool in the brackets in the client

As for your current issue, I don’t see LoadAnimation used in any of the scripts you sent, can you send your current version of the erroring script?