Custom FPS ViewModel causes player character to move

I have made an First Person viewmodel for my tools with help of this tutorial: “https://www.youtube.com/watch?v=tolnsCxgkpk&t=1s

When an tool is equipped I put the custom made “ViewModel” made for that specific tool inside the game.Workspace.Camera locally and then I run this function

runService.RenderStepped:Connect(function()
	if player.Character.Humanoid.Health <= 0 then
		local viewModel = camera:FindFirstChild("ViewModel")
		if viewModel then
			viewModel:Destroy()
		end
	end

	if equipped == true then
		if camera:FindFirstChild("ViewModel") ~= nil then
			camera.ViewModel:SetPrimaryPartCFrame(camera.CFrame)
			for i,v in pairs(camera.ViewModel:GetChildren()) do
				if v:IsA("BasePart") then
					v.CanCollide = false
				end
			end

			local mouseDelta = game:GetService("UserInputService"):GetMouseDelta() / 50

			local swayX = math.clamp(mouseDelta.X, -0.3, 0.3)
			local swayY = math.clamp(mouseDelta.Y, -0.3, 0.3)

			swayCF = swayCF:Lerp(CFrame.new(swayX, swayY, 0), 0.3)

			camera.ViewModel:SetPrimaryPartCFrame(camera.CFrame * swayCF)
		end
	end
end)

But when the viewModel is equipped it causes my character to kinda teleport just a small distance as you can see in this gyazo GIF “https://gyazo.com/c8688cb08eef4b5e5930ab87d795de01”.

This problem only happends when the player is fully zoomed in aswell. (But its an first person game so players will forced to be fully zoomed in)

All the parts are Collide = false, also Massless and so on. I have no clue whats causing the issue exactly.

Make sure the tool’s handle isn’t anchored, as this will cause your character to move to the position
Edit: wait… I didn’t read the “this only happens in first person”… Can you show a video of the character in third person? Walk around a bit and then try equipping the weapon in first person

I managed to fix it, on my “ViewModel” I had an “HumanoidRootPart”, “Head”, the arms and the “weapon”. Removing the “HumanoidRootPart” somehow fixed it.

Huh, weird, but atleast its solved! Good luck with your development!
Also, if you plan on adding multiple weapons, I suggest you check out this great tutorial by @BlackShibe on how to make a solid fps framework. I think it can really elevate your current framework:

1 Like