Character moving by itself when looking down and crouching

  1. What do you want to achieve?
    I have created a head bobbing, sprinting and crouching character local script for a game I am working on.

  2. What is the issue?
    When I look down, while crouching in first person, the character slowly moves forward. I am also unable to move backwards or to the side at all when crouching in first person.

  3. What solutions have you tried so far?
    I’ve attempted to see any character movement, but there is nothing on it. My idea is that the character is somehow following the camera offset in first person, moving it. I have no idea how to turn that off.

The code below is a localcharacterscript and controls the camera. The remoteevents connect to a serverside that controls how fast the player is going. The Lightpart controls a flashlight and works fine, but is still part of the script.

local runService = game:GetService("RunService")
local userInputService = game:GetService("UserInputService")


local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
RegOffset = Vector3.new(0,0,0)
local Crouching = false
local Running = false
Extremity = .6
TimeTo = 2.5

function updateBobbleEffect()
	local currentTime = tick()
	local bobble = Vector3.new(0,0,0)
	if humanoid.MoveDirection.Magnitude > 0 then -- we are walking
		local bobbleX = math.cos(currentTime * TimeTo) * Extremity
		local bobbleY = math.abs(math.sin(currentTime * TimeTo)) * Extremity

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

		humanoid.CameraOffset = humanoid.CameraOffset:lerp(bobble, 0.25)
	else -- we are not walking
		humanoid.CameraOffset = humanoid.CameraOffset:lerp(RegOffset, 0.05)
	end
	game.Workspace.LightPart.CFrame = game.Workspace.LightPart.CFrame:Lerp(game.Workspace.CurrentCamera.CFrame - bobble, .1)
end

function Key(KeyHit)
	print("key")
	if KeyHit.KeyCode == Enum.KeyCode.LeftControl or KeyHit.KeyCode ==  Enum.KeyCode.ButtonL1 then
		print("crouch")
		if Crouching == true then
			Crouching = false
			Running = false
			RegOffset = Vector3.new(0,0,0)
			Extremity = .6
			TimeTo = 5
			script.Parent.CrouchRemote:FireServer(false)
		else
			Crouching = true
			RegOffset = Vector3.new(0,-2,0)
			Extremity = .3
			TimeTo = 2.5
			script.Parent.CrouchRemote:FireServer(true)
		end
	elseif KeyHit.KeyCode == Enum.KeyCode.LeftShift or KeyHit.KeyCode == Enum.KeyCode.ButtonR1 then
		print("run started")
		Running = true
		Crouching = false
		RegOffset = Vector3.new(0,-0.3, 0)
		Extremity = 1
		TimeTo = 7
		script.Parent.RunRemote:FireServer(true)
	end
end

function EndKey(KeyHit)
	if KeyHit.KeyCode == Enum.KeyCode.LeftShift or KeyHit.KeyCode == Enum.KeyCode.ButtonR1 then
		print("run ended")
		Running = false
		RegOffset = Vector3.new(0,0,0)
		Extremity = .3
		TimeTo = 2.5
		script.Parent.RunRemote:FireServer(false)
	end
end

runService.RenderStepped:Connect(updateBobbleEffect)
userInputService.InputBegan:Connect(Key)
userInputService.InputEnded:Connect(EndKey)

Can you show the Crouch Remote Handler I have a feeling you probably set the hip-height too low and player begins to slide. Or if u meant actually like walking around ill have to look some more.

Sure thing, I didn’t know you had to change hip hight when moving the camera, should I be doing that?

local CrouchRemote = Instance.new("RemoteEvent")
CrouchRemote.Parent = script.Parent
CrouchRemote.Name = "CrouchRemote"
local MovementNoise = 16

local RunRemote = Instance.new("RemoteEvent")
RunRemote.Parent = script.Parent
RunRemote.Name = "RunRemote"

function Crouch(plr, IfCrouch)
	if plr == game.Players:GetPlayerFromCharacter(script.Parent) then
		if IfCrouch == true then
			MovementNoise = 8
			script.Parent.Humanoid.WalkSpeed = 3
		else
			MovementNoise = 16
			script.Parent.Humanoid.WalkSpeed = 6
		end
	end
end

function Sprint(plr, IfRun)
	if plr == game.Players:GetPlayerFromCharacter(script.Parent) then
		if IfRun == true then
			MovementNoise =  64
			script.Parent.Humanoid.WalkSpeed = 16
		else
			MovementNoise = 16
			script.Parent.Humanoid.WalkSpeed = 6
		end
	end
end

CrouchRemote.OnServerEvent:Connect(Crouch)
RunRemote.OnServerEvent:Connect(Sprint)

No you don’t need to change the hip-height at all but if u make the hip-height too low it can cause the player to move/slide. I thought it was causing your problem but it appears now. That it isn’t the case.

Ok, thank you for the help though.