Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to change Motor6D rig?

How do i change the Motor6D of an object so that it will move from one part to another?

*I Have a rig, which has a rifle (part with a mesh inside) that has a Motor6D connecting it to the torso.

Image

How do i make it so that it switches to the Motor6D connecting the rifle to the players arms(as if he was holding it)? Image

Thanks :D

1 answer

Put this inside a tool...

Handle = nil

function onUnequipped()
	if script.Parent.Parent == workspace or script.Parent.Parent.className ~= "Backpack" then
		return
	end

	local char = script.Parent.Parent.Parent.Character
	if char ~= nil then
		local torso = char:findFirstChild("Torso")
		local tool = char:findFirstChild(script.Parent.Name)
		if torso ~= nil and tool == nil then
			local model = Instance.new("Model")
			model.Name = script.Parent.Name
			model.Parent = char

			handle = script.Parent.Handle:clone()
			handle.CanCollide = false
			handle.Name = script.Parent.Name
			handle.Parent = model

			local weld = Instance.new("Weld")
			weld.Name = "BackWeld"
			weld.Part0 = torso
			weld.Part1 = handle
			weld.C0 = CFrame.new(-1,-1.02,0)
			weld.C0 = weld.C0 * CFrame.fromEulerAnglesXYZ(math.rad(-170),math.rad(-180),-20.5)
			weld.Parent = handle
		end
	end
end

script.Parent.Unequipped:connect(onUnequipped)

function onEquipped()
	if handle ~= nil then 
		handle.Parent:remove()
	end
end

script.Parent.Equipped:connect(onEquipped)
		

This discussion is preserved as it was. New answers, comments, and votes are closed.