I was making a viewmodel for a project I’ve been working on the past few days. Here’s the code:
This is in a local script in the GUI.
local Camera = workspace.CurrentCamera
local RunService = game:GetService("RunService")
RunService.RenderStepped:Connect(function()
if script.Parent.ViewmodelObject.Value == nil then return end
script.Parent.ViewmodelObject.Value.HumanoidRootPart.CFrame = (Camera.CFrame - Vector3.new(0,1,0))
end)
Nothing special about it, at least you would expect it to do what is intended. However, this script starts off disabled, and when an event goes off, another local script re-enables it. The RenderStepped function still technically works, but in game, you can clearly see jittering in the view model and something is not working as intended.
This is the part of another script which dictates whether the renderer is enabled or not.
script.ViewModelActivated.Event:Connect(function()
if game.ReplicatedStorage.ViewModels:FindFirstChild(script.ViewModelName.Value) == nil then
warn(404)
return end
viewModel = game.ReplicatedStorage.ViewModels:FindFirstChild(script.ViewModelName.Value).ViewModel:Clone()
viewModel.Parent = workspace
script.ViewmodelObject.Value = viewModel
script.Renderer.Enabled = true
viewModel["Right Arm"].Color = Character["Right Arm"].Color
viewModel["Left Arm"].Color = Character["Left Arm"].Color
EquipAnimation = viewModel.Animations.Equip
EquipTrack = viewModel.Humanoid:LoadAnimation(EquipAnimation)
IdleAnimation = viewModel.Animations.Idle
IdleTrack = viewModel.Humanoid:LoadAnimation(IdleAnimation)
EquipTrack:Play()
task.spawn(PlayIdle)
end)
script.ViewModelDeactivated.Event:Connect(function()
viewModel = nil
script.ViewmodelObject.Value = nil
script.Renderer.Enabled = false
end)
You’ll notice two lines which enable script.Renderer and disable script.Renderer
When these two lines are removed from the script, the view model works as intended.
Why does this happen? I have a solution, I just wish there was a way I could keep this implementation without changing things (or get back the life I spent wasted on figuring this out), but unfortunately that’s the way things have to be for this to work.
Note: The animations don’t appear in the first clip, but this is not the problem, please ignore that. The jittering happens with or without animations it truly doesn’t matter.