Viewmodel not following camera offset issue

this is my first time making a post so if there are any mistakes i made please tell me thanks

so i have been having this issue where when i set the viewmodels position to the camera then also have another script that controls some offset for the camera the viewmodel will not follow the camera offset at all
i want the viewmodel to follow the camera offset too

video:

i also made a place file so you can see the problem for yourself:
viewmodel camera offset issue.rbxl (61.0 KB)

heres some code from the place file:

--client viewmodel script
local rs = game:GetService("RunService")
local tool = script.Parent
local viewmodel = game.ReplicatedStorage.viewmodel:Clone()


local connection = nil
tool.Equipped:Connect(function()
	viewmodel.Parent = workspace
	connection = rs.RenderStepped:Connect(function(dt)
		viewmodel.CFrame = game.Workspace.Camera.CFrame * tool.viewmodelOffset.Value
	end)
end)

tool.Unequipped:Connect(function()
	viewmodel.Parent = game.ReplicatedStorage
	connection:Disconnect()
end)
--client camera offset script
local rs = game:GetService("RunService")
local cam = game.Workspace.Camera


rs.RenderStepped:Connect(function(dt)
		cam.CFrame = cam.CFrame * CFrame.new(math.sin(time() * 5) * 1,0,0) --camera offset stuff
end)
1 Like

The way the spring module you use sets the target as a fixed offset from the viewmodel thus it will bounce.

Try only using springs for rotational movements and having the fixed gun in a fixed offset.

i dont think you understand in the first video only the camera is moving when you jump the camera has an offset that makes it go down then up to make it look smooth and also the viewmodel doesnt use any springs its just being set to the cameras cframe plus some offsets and sway(not using spring for sway)

if youre adding the offset correctly then it might be that the offset when the runservice loop runs is not at the right timing

try changing runservice priority with this

:BindToRenderStep("youCanPutAnyStringHere", Enum.RenderPriority.Camera.Value - 1, function(dt : number)
1 Like

I fixed it
https://gyazo.com/3580cfcbff9fa120c7c8fb30a4f42c5a

1 Like

Renderstep is very sensitive so what I did is change the offset of the camera sway and change the view model on the same function.

thank you so much! i had to remove the little “-1” you added but it works very well
also just asking how would i disconnect the function? (nvm im 0.00005 iq)