Bobbing viewmodel doesn't work after death

Hello! I made a bobbing system for my FPS Game, it works fine, until the player dies…

function bobView()
	coroutine.wrap(function()
		if humanoid.MoveDirection.Magnitude > 0 then
			if humanoid.WalkSpeed == game.StarterPlayer.CharacterWalkSpeed then
				boboffset = boboffset:Lerp(CFrame.new(math.cos(tick() * 1.2) * .01 ,-humanoid.CameraOffset.Y/10, 0) * CFrame.Angles(0, math.sin(tick()* -1) * -.01, math.cos(tick() * -1.2) *.02), .08) 
			elseif humanoid.WalkSpeed > game.StarterPlayer.CharacterWalkSpeed then
				boboffset = boboffset:Lerp(CFrame.new(.7 ,-humanoid.CameraOffset.Y/6, -.5) * CFrame.Angles(-.3, .6, math.cos(tick() * -7) *.09), .05) 
			elseif humanoid.WalkSpeed < game.StarterPlayer.CharacterWalkSpeed then
				boboffset = boboffset:Lerp(CFrame.new(math.cos(tick() * 1.5) * .05 ,-humanoid.CameraOffset.Y/10, 0) * CFrame.Angles(0, math.sin(tick()* -1.5) * -.005, math.cos(tick() * -1.5) *.015), .08) 
			elseif isAiming == true then
				boboffset = boboffset:Lerp(CFrame.new(math.cos(tick() * .5) * .01 ,-humanoid.CameraOffset.Y/11, 0) * CFrame.Angles(0, math.sin(tick()* -.2) * -.01, math.cos(tick() * -.3) *.02), .08) 
			end
		elseif humanoid.MoveDirection.Magnitude == 0 and isAiming == false then
			boboffset = boboffset:Lerp(CFrame.new(math.cos(tick() *.1) * .01,-humanoid.CameraOffset.Y/3, math.cos(tick() *.3) * .05), .1)
		elseif humanoid.MoveDirection.Magnitude == 0 and isAiming == true then
			boboffset = boboffset:Lerp(CFrame.new(0,-humanoid.CameraOffset.Y/3, 0), .1)
		end
	end)()
end

As you can see from the video, the first bit is when the player spawned, the bobbing works and all, but the second bit, where the ForceField is visible, the bobbing just doesnt work anymore.

runService.RenderStepped:Connect(function(dt)

	if viewmodel ~= nil and settings ~= nil then
        -- there is stuff here but it's not related to the problem
	end

	bobView() -- not related to rest of script
end)

If somebody can help me I will appreciate it very much!

This could be caused by the humanoid variable not being changed to the new Humanoid after the character respawns, so the script is only getting the humanoid.MoveDirection from the Humanoid that has already been Removed. Try using the following to set the new Humanoid after the character spawns:

player.CharacterAdded:Connect(function(character)
	humanoid = character:WaitForChild("Humanoid")
end)
1 Like

You can just move the script to StarterCharacterScripts so it gets the new character after death, if you can’t then do what @usr_updated said.

1 Like

Thanks so much, I missed such an easy fix!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.