Switching weapons in Viewmodels

For testing I’ve been putting my guns inside the arms viewmodel, but now that I have made multiple guns how can I switch between them without creating multiple viewmodels and just changing out the gun model?

Would I create a motor6d for all the guns and the link them to the arms but keep them in replicated? Would that create issues for animations? Scripting in the motors seems extremely tedious to do for multiple models so I’m hoping there is a better method.

Just do what Roblox does when you equip a tool. Have one viewmodel, but the gun tells it where the arms should be positioned.

You shouldn’t need a Motor6D for the tool grip. A Weld would be more suitable.

sorry for the late reply, I’m not really sure I get what you mean.

Would a weld make it harder to animate the right hand moving, since the gun would move with it. Example: animating an inspect animation with an m4 and slapping the forward assist with the right hand

Oh, I meant when you attach the tool to the arm. I guess a Motor6D can be used but you wouldn’t mainly use it for recoil.

I’ve just recently started creating a viewmodel system to replace the current FPS system I have, and I ran into this exact same question. The problem is that if you have multiple viewmodels, they won’t be consistent. So, I’m still probably going to have a viewmodel of the arms, but the gun’s settings will tell it where the arms should be positioned. You can also animate them using the animation editor.

An approach I use is to:

  • 1: Create a copy of the arms and weapon you want
  • 2: Parent the weapon to the arms and then the arms to the camera
  • 3: Create a motor6d then attach the weapon primarypart to the viewarms primarypart

I do this every time a weapon is equipped but, you could cache them for later use if it becomes a performance concern.

Here’s a snippet from my own fps system

local function EquipItem(slot)
	if (fpscc.current_slot == slot) then return
	elseif (fpscc.Inventory.slots[slot] == nil) then return
	else fpscc.current_slot = slot end

	-- notify server
	fps_global.network.action0:FireServer(slot)

	-- unload previous item
	if (fpscc.ibehavior ~= nil) then
		fpscc.ibehavior.Unload()
		fpscc.viewmodel:Destroy()
	end

	-- setup viewmodel
	local idata = fpscc.Inventory.slots[slot].data
	local viewarms = fps_global.assets.view.view_arms0:Clone()
	local viewitem = idata.path.models.fp_model:Clone()
	viewitem.Name = "viewitem"
	viewarms.Name = "viewmodel"
	viewitem.Parent = viewarms
	viewarms.Parent = workspace.Camera
	viewarms.PrimaryPart.CFrame = CFrame.new(0,-100,0)

	-- attach item to arms
	local itemMotor = Instance.new("Motor6D")
	itemMotor.Name = "ItemMotor"
	itemMotor.Part0 = viewarms.PrimaryPart
	itemMotor.Part1 = viewitem.PrimaryPart
	itemMotor.Parent = viewarms.PrimaryPart

	fpscc.viewmodel = viewarms
end
1 Like