How to disable sprint while crouch is active?

Hello,

So I got a working sprint and crouch system and put them both into a same LocalScript inside StarterCharacterScripts. Everything works fine except that you’re currently able to run while crouching. How would I disable the sprinting as you’re crouching?

Here’s my script:

-- Crouching System

local UserInputService = game:GetService("UserInputService")
local character = script.Parent
local Humanoid = character:WaitForChild("Humanoid")
local CrouchAnimation = Humanoid:LoadAnimation(script:WaitForChild("CrouchAnimation"))
local isCrouching = false

Humanoid.Running:Connect(function(speed)
	if speed > 0 then
		CrouchAnimation:AdjustSpeed(1)
	else
		CrouchAnimation:AdjustSpeed(0)
	end
end)

UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.C then
		if not isCrouching then
			isCrouching = true
			CrouchAnimation:Play()
			Humanoid.CameraOffset = Vector3.new(0,-0.98,0)
			CrouchAnimation:AdjustSpeed(0)
			Humanoid.WalkSpeed = 5
		else
			CrouchAnimation:Stop()
			Humanoid.CameraOffset = Vector3.new(0,0,0)
			Humanoid.WalkSpeed = 12
			isCrouching = false
		end
	end
end)

-- Sprint System

local uis = game:GetService('UserInputService')
local player = game.Players.LocalPlayer


uis.InputBegan:Connect(function(input)
	local char = player.Character
	local hum = char:WaitForChild("Humanoid")
	if input.UserInputType == Enum.UserInputType.Gamepad1 then
		if input.KeyCode == Enum.KeyCode.ButtonR1 then
			hum.WalkSpeed = 21
		end
	end
end)

uis.InputEnded:Connect(function(input)
	local char = player.Character
	local hum = char:WaitForChild("Humanoid")
	if input.UserInputType == Enum.UserInputType.Gamepad1 then
		if input.KeyCode == Enum.KeyCode.ButtonR1 then
			hum.WalkSpeed = 12
		end
	end
end)

uis.InputBegan:Connect(function(input)
	local char = player.Character
	local hum = char:WaitForChild("Humanoid")
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.LeftShift then
			hum.WalkSpeed = 21
		end
	end
end)

uis.InputEnded:Connect(function(input)
	local char = player.Character
	local hum = char:WaitForChild("Humanoid")
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.LeftShift then
			hum.WalkSpeed = 12
		end
	end
end)


I’ve look up similar threads and such but nothing really helped. I’d appreciate your help!

add onto one of your if statements in your print system with smthn like

and not isCrouching then

image

Did so now but the problem remains? What could I be missing?

Edit:
Nevermind, I didn’t notice that the original seperate script for the run system was still there. Deleted it and now fixed! Thanks for the help!

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