Problem With: Bobbing Script intensifying when running, and less when walking

Hey all Dev’s,

I ran in to a problem with one of my scripts for my game that bobs the players screen when walking and running, the problem I have is that I want the bobbing to be more intense when running. Before hand I thought if I just made the script check the players walk speed and if it was over 30 then it would intensify the bobbing. And if it was less then 30 then it would lessen. But as I wrote it out is seems to not work. I just want to see how to write it out in such a way that I can get the result I want.

Thank you all for any help I can get on this madder.

local runService = game:GetService("RunService")

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")


local Humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
local Player = game.Players.LocalPlayer

if Humanoid.WalkSpeed < 30 then
	function updatedBobbleEffct()
		local currentTime = tick()
		if humanoid.MoveDirection.Magnitude > 0 then
			local bobbleX = math.cos(currentTime * 0) * 1
			local bobbleY = math.abs(math.sin(currentTime * 4)) * 1

			local bobble = Vector3.new(bobbleX, bobbleY, 0)

			humanoid.CameraOffset = humanoid.CameraOffset:lerp(bobble, .25) --25
		else
			humanoid.CameraOffset = humanoid.CameraOffset * .75 --75
		end
	end
	runService.RenderStepped:Connect(updatedBobbleEffct)
	end 
	
	if Humanoid.WalkSpeed > 30 then
		function updatedBobbleEffct()
			local currentTime = tick()
			
			if humanoid.MoveDirection.Magnitude > 0 then
				local bobbleX = math.cos(currentTime * 0) * 1
				local bobbleY = math.abs(math.sin(currentTime * 4)) * 1

				local bobble = Vector3.new(bobbleX, bobbleY, 0)

				humanoid.CameraOffset = humanoid.CameraOffset:lerp(bobble, .05) --25
			else
				humanoid.CameraOffset = humanoid.CameraOffset * .1 --75
			end
		end
	end

	runService.RenderStepped:Connect(updatedBobbleEffct)

If you can, I would appreciate any help in showing what I’m doing wrong :smiley: .

1 Like

Instead of writing 2 functions and 2 runservice events, create one function only, and inside the function check if speed is higher/lower than 30 and change the numbers with how you want them to be. Connect that function to the runservice as you did.

3 Likes

Ok thanks! Ill go try it out, but that should work.

1 Like

If I put in (If false then) would that work?

**

You can’t put true/false statements in there.

if humanoid.WalkSpeed >= 30 then
-- bobble
elseif humanoid.WalkSpeed < 30 then
-- bobble
1 Like

This happens when I do that unless I’m writing it out wrong.

Elseif statements only work if you first have a if statement, it can’t really have an “else” if you don’t have something in the first place

1 Like