Why is my viewmodel glitching like this?


For whatever reason my viewmodel started glitching like this for seemingly no reason, does anyone know why?
Script:

game.Players.LocalPlayer.CharacterAdded:Wait()

game.Players.LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
game:GetService("UserInputService").MouseIconEnabled = false

local viewModel = game.ReplicatedStorage.ViewModel:Clone()
viewModel.Parent = workspace
viewModel.PrimaryPart = viewModel["Primary Part"]

local equipAnim = viewModel.AnimationController:LoadAnimation(script.Equip)

local tweenInfo = TweenInfo.new(
	0.05,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

game:GetService("RunService").RenderStepped:Connect(function()
	game.TweenService:Create(viewModel.Value, tweenInfo, {Value = workspace.CurrentCamera.CFrame}):Play()
end)

viewModel.Value:GetPropertyChangedSignal("Value"):Connect(function()
	viewModel:SetPrimaryPartCFrame(viewModel.Value.Value)
end)

game:GetService("UserInputService").InputBegan:Connect(function(inputType)
	if inputType.KeyCode == Enum.KeyCode.One then
		equipAnim:Play()
	end
end)

couldn’t you just do this?

Viewmodel:SetPrimaryPartCFrame(workspace.CurrentCamera.CFrame)

and just put that into a renderstepped connection since what youre doing is putting the camera cframe to a value every renderstepped then positioning the viemodel to that value why do all of that when you can just do what i typed above

The code I have gives it a realistic swaying effect when you move the camera
You can use setprimarypartcframe in a tween, so I had to use that

I think it’s a weird way Roblox does optimisation with the viewport. It hides parts even when it really shouldn’t. Try testing it with your viewport camera further back, and see if the model still disappears.

Try printing the value every frame to make sure there aren’t any weird values.

Probably a NaN value rather than Roblox itself.