Snappy Viewmodels

So a week ago I wrote this simple VM code because I wanted to experiment with FPS type assets however, as seen in the video the viewmodel seems to be pretty snappy and I need it to be smoothly welded to the players camera.

here is my code:

local vem = "VEM"

script.Parent.Equipped:Connect(function()
	local viewmodel = game.ReplicatedStorage.VM:Clone()
	viewmodel.Parent = workspace.Camera
	local weapon = game.ReplicatedStorage.Models[script.Parent.Name]:Clone()
	weapon.Parent = viewmodel

	local char = viewmodel:WaitForChild("Torso")

	local M6D = Instance.new("Motor6D", char)
	M6D.Name = "ToolGrip"

	char.ToolGrip.Part0 = char
	char.ToolGrip.Part1 = viewmodel[script.Parent.Name].BodyAttach

	local limbs = viewmodel:GetDescendants()
	for i,v in pairs(limbs)do
		if v:IsA("BasePart")then do
				PhysicsService:SetPartCollisionGroup(v, vem)
			end
		end
	end

	local humanoid = viewmodel:WaitForChild('Humanoid')
	local Id = humanoid:LoadAnimation(viewmodel[script.Parent.Name]:WaitForChild('Hold'))

Id:Play()

game:GetService("RunService").Stepped:Connect(function()
		viewmodel.Head.CFrame = workspace.CurrentCamera.CFrame
	end)
end)

any help very is appreciated

2 Likes

Use renderstepped as it runs before the camera updates to guarantee that the model is always in front of the camera.

1 Like

try using .RenderStepped instead of .Stepped

1 Like

do you mean like this?

local PhysicsService = game:GetService("PhysicsService")
local vem = "VEM"

script.Parent.Equipped:Connect(function()
	local viewmodel = game.ReplicatedStorage.VM:Clone()
	viewmodel.Parent = workspace.Camera
	local weapon = game.ReplicatedStorage.Models[script.Parent.Name]:Clone()
	weapon.Parent = viewmodel
game:GetService("RunService").Stepped:Connect(function()

		local char = viewmodel:WaitForChild("Torso")

		local M6D = Instance.new("Motor6D", char)
		M6D.Name = "ToolGrip"

		char.ToolGrip.Part0 = char
		char.ToolGrip.Part1 = viewmodel[script.Parent.Name].BodyAttach

		local limbs = viewmodel:GetDescendants()
		for i,v in pairs(limbs)do
			if v:IsA("BasePart")then do
					PhysicsService:SetPartCollisionGroup(v, vem)
				end
			end
		end

		local humanoid = viewmodel:WaitForChild('Humanoid')
		local Id = humanoid:LoadAnimation(viewmodel[script.Parent.Name]:WaitForChild('Hold'))

		Id:Play()
		viewmodel.Head.CFrame = workspace.CurrentCamera.CFrame
	end)
end)
1 Like

oh this fixed it now thanks for the help!

1 Like