Issue with Motor6D Animation

  1. What do you want to achieve? Keep it simple and clear!
    Animate a gun with moving parts

  2. What is the issue? Include screenshots / videos if possible!
    My animation works fine in the editor, but in game some of the parts are offset (such as the gun slide) and other parts move in ways they shouldnt.

Video demonstration: WeirdAnimationBug - YouTube

I should note that all parts are aligned properly and look normal, and are inside (connected) to the torso via motor6d. I also did not copy a motor6d from a body part, so its C0 and C1 Values are all 0

This is my weapon code below


local origin = script.Parent:WaitForChild("Origin")

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local mouse = player:GetMouse()

local tool = script.Parent

local Steyrshoot = game.ReplicatedStorage.Steyrfire
local BulletFolder = game.Workspace.Bullets

local WhoFired = game.ReplicatedStorage.WhoFired

local UIS = game:GetService('UserInputService') -- for checking keys
local ui = script.Parent:WaitForChild("ScreenGui") --get screengui

local debounce = false
local cooldown = 0.15

local doing = false

local animShoot = Instance.new("Animation")
animShoot.AnimationId = "http://www.roblox.com/Asset?ID=11822160775"
local track1

ammotable = game.Workspace.Map.MainMap.Ammotable.AmmotableMain

local steyrammo = 10 -- ammo in a mag
local steyrmags = 2 -- magazines

tool.Equipped:Connect(function()
	game.ReplicatedStorage.ConnectM6D:FireServer(tool.BodyAttach)

	char.Torso.ToolGrip.Part0 = char.Torso
	char.Torso.ToolGrip.Part1 = tool.BodyAttach
	
	mouse.Icon = "rbxassetid://11821888629"
	ScreenGui = ui:Clone()
	ScreenGui.Parent = game.Players.LocalPlayer.PlayerGui
	ScreenGui.Body.Ammo.Text = (steyrammo)
	ScreenGui.Body.Mags.Text = (steyrmags)
	lookat = true
	while lookat  do
		local Player = game.Players.LocalPlayer
		local Mouse = Player:GetMouse()
		local Character = Player.Character
		local Root = Character.HumanoidRootPart

		local RootPos, MousePos = Root.Position, Mouse.Hit.Position
		Root.CFrame = CFrame.new(RootPos, Vector3.new(MousePos.X, RootPos.Y, MousePos.Z))
		task.wait()
	end
end)

tool.Unequipped:Connect(function()
	mouse.Icon = [[ ]]
	ScreenGui:Destroy()
end)

local tabledebounce = false

local function TableHit(hit)
	local playerWhoTouched = game.Players:GetPlayerFromCharacter(hit.Parent)
	if playerWhoTouched == player then
		if tabledebounce == false then
			if player.Character:FindFirstChild("Steyr M") ~= nil then
				tabledebounce = true
				steyrmags = 2
				steyrammo = 10
				ScreenGui.Body.Ammo.Text = (steyrammo)
				ScreenGui.Body.Mags.Text = (steyrmags)
				tool.Origin.TakeAmmo:Play()
				task.wait(3)
				tabledebounce = false
			end
		end
	end
end

ammotable = game.Workspace.Map.MainMap.Ammotable.AmmotableMain
ammotable.Touched:Connect(TableHit)

ammotable2 = game.Workspace.Map.MainMap.Ammotable2.AmmotableMain
ammotable2.Touched:Connect(TableHit)

ammotable3 = game.Workspace.Map.MainMap.Ammotable3.AmmotableMain
ammotable3.Touched:Connect(TableHit)




UIS.InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.R then
		if doing == false then
			if steyrmags > 0 then
				if debounce == false then
					if steyrammo < 10 then
						if player.Character:FindFirstChild("Steyr M") ~= nil then
							debounce = true
							script.Parent.Origin.ak47reload:Play()
							steyrmags = steyrmags - 1
							local animReload = Instance.new("Animation")
							animReload.AnimationId = "http://www.roblox.com/Asset?ID=11822622019" 
							local track = script.Parent.Parent.Humanoid:LoadAnimation(animReload)
							track.Priority = Enum.AnimationPriority.Action4
							track.Looped = false
							track:AdjustSpeed(1)
							track:Play()
							task.wait(1.5)
							steyrammo = 10
							ScreenGui.Body.Ammo.Text = (steyrammo)
							ScreenGui.Body.Mags.Text = (steyrmags)
							debounce = false
						end
					end
				end
			end
		end	
	end
end)

tool.Activated:Connect(function()
if steyrammo > 0 then
		if debounce == false then
			debounce = true 
				
			steyrammo = steyrammo - 1
			ScreenGui.Body.Ammo.Text = (steyrammo)
				
			local Player = game:GetService('Players').LocalPlayer
			local Character = Player.Character or Player.CharacterAdded:Wait()
			local Humanoid = Character:WaitForChild('Humanoid')
			
			local mousePosition = mouse.Hit.p
			local originPosition = origin.Position
			
			
			track1 = script.Parent.Parent.Humanoid:LoadAnimation(animShoot)
			track1.Priority = Enum.AnimationPriority.Action4
			track1.Looped = false
			track1:Play()
		
			local p = game.Players.LocalPlayer
			
			WhoFired:FireServer(p)
			
			Steyrshoot:FireServer(mousePosition, originPosition)
			script.Parent.Origin.M249fire:Play()
			wait(cooldown)
			
			local Player = game.Players.LocalPlayer
			local Character = Player.Character
			local Root = Character.HumanoidRootPart

			local Mouse = Player:GetMouse()
			local RunService = game:GetService("RunService")
			
			local RootPos, MousePos = Root.Position, Mouse.Hit.Position
			Root.CFrame = CFrame.new(RootPos, Vector3.new(MousePos.X, RootPos.Y, MousePos.Z))
			
			local Player = game:GetService('Players').LocalPlayer
			local Character = Player.Character or Player.CharacterAdded:Wait()
			local Humanoid = Character:WaitForChild('Humanoid')
			
			task.wait(0.06)
			debounce = false
		end
	end
end)

local animIdle = Instance.new("Animation")
animIdle.AnimationId = "http://www.roblox.com/Asset?ID=11822100573" 
local animEquip = Instance.new("Animation")
animEquip.AnimationId = "http://www.roblox.com/Asset?ID=11822664268" 
local track
local trackequip
tool.Equipped:Connect(function()
	debounce = true
	if player.Character:FindFirstChild("Steyr M") ~= nil then
	script.Parent.Origin.M2equip:Play()
	track = script.Parent.Parent.Humanoid:LoadAnimation(animEquip)
	track.Priority = Enum.AnimationPriority.Action4
	track.Looped = false
	track:Play()
	task.wait(0.1)
	track = script.Parent.Parent.Humanoid:LoadAnimation(animIdle)
	track.Priority = Enum.AnimationPriority.Action2
	track.Looped = true
	track:Play()
end
	debounce = false
end)

debounce = false

tool.Unequipped:Connect(function()
	game.ReplicatedStorage.DisconnectM6D:FireServer()
	lookat = false
	if track then
		track:Stop()
	end
end)

-- 11702743666 Fire
-- 11689904047 Idle
-- 11702935791 Equip

You probably should copy the C0 and C1, it may be orientated differented causing the change in position to be on a different new axis.

Of which part though? When I attached it to the torso it was aligned as it should be, and im not sure why it would make parts fly around like that without the C values