Help disabling sprinting while crawling

Ok I will rn hold up I will tell you if it works

Ok I did it but every time I put crouching it goes red under it

And I put it at the very end is that gonna be a problem

I got one error when testing it, I can’t sprint at all and the error says

Move it underneath uis and sprint it’s erroring because the event is being called before the script defines those. Also, make the sprint function lowercase

Sorry but move what underneath uis

The event listener
image

So put if input.key code==enum and u know the rest under sprint began? If so I did it and it still said error

Sorry bro I am stupid at scripting I’m trying to learn it

Don’t worry, copy and paste the code, I’ll show you what I mean

uis.InputBegan:Connect(function(input, proccess)

Sprint(“Began”)

if input.KeyCode == Enum.KeyCode.LeftShift and not crouching then

end

end)

– Variables

local uis = game:GetService(“UserInputService”)

local player = game.Players.LocalPlayer

local char = player.Character or player.CharacterAdded:Wait()

– For the Staminacv

local isSprinting = false

local MaxStamina = 1300

local stamina = MaxStamina

local staminaBar = script.Parent:WaitForChild(“StaminaBar”)

local staminaButton = script.Parent:WaitForChild(“SprintButton”)

– Functions

local function sprint(SType)

local humanoid = char:FindFirstChild(“Humanoid”)

if SType == “Began” then

isSprinting = true

humanoid.WalkSpeed = humanoid.WalkSpeed * 1.6

elseif SType == “Ended” then

isSprinting = false

humanoid.WalkSpeed = 16

end

end

– Stamina: Check if it on moblie

if uis.TouchEnabled then

staminaButton.Visible = true

end

– For PC

uis.InputBegan:Connect(function(input, process)

if input.KeyCode == Enum.KeyCode.LeftShift then

sprint(“Began”)

end

end)

uis.InputEnded:Connect(function(input, process)

if input.KeyCode == Enum.KeyCode.LeftShift then

sprint(“Ended”)

end

end)

– For Moblie

staminaButton.ImageButton.MouseButton1Down:Connect(function()

sprint(“Began”)

end)

staminaButton.ImageButton.MouseButton1Up:Connect(function()

sprint(“Ended”)

end)

– Updating

game:GetService(“RunService”).RenderStepped:Connect(function()

local humanoid = char:FindFirstChild(“Humanoid”)

if stamina == 0 and isSprinting then

sprint(“Ended”)

end

if isSprinting and humanoid.MoveDirection.Magnitude > 0 then

stamina = stamina - 4 – Run

else

stamina = stamina + 1.8 – Rest

end

stamina = math.clamp(stamina,0,MaxStamina)

staminaBar.BlueFrame.Size = UDim2.new(stamina/MaxStamina,0,1,0)

end)

uis.InputBegan:Connect(function(Input, Processed)

if Input.KeyCode == Enum.KeyCode.LeftShift and not crouching then

sprint(“Began”)

end

end)

-- Variables

local uis = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()

-- For the Staminacv
local isSprinting = false
local MaxStamina = 1300
local stamina = MaxStamina
local staminaBar = script.Parent:WaitForChild("StaminaBar")
local staminaButton = script.Parent:WaitForChild("SprintButton")

-- Default variables
local crouching = false

-- Functions
local function sprint(SType)
	local humanoid = char:FindFirstChild("Humanoid")
	
	if SType == "Began" then
		isSprinting = true
		humanoid.WalkSpeed = humanoid.WalkSpeed * 1.6
	elseif SType == "Ended" then
		isSprinting = false
		humanoid.WalkSpeed = 16
	end

end

-- Stamina: Check if it on moblie
if uis.TouchEnabled then
	staminaButton.Visible = true
end

-- For PC

-- Put this listener here 
uis.InputBegan:Connect(function(input, proccess)
	if input.KeyCode == Enum.KeyCode.LeftShift and not crouching then
		sprint("Began") -- lower case 'sprint' because that's how the function was defined
	end
end)

uis.InputEnded:Connect(function(input, process)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		sprint("Ended")
	end
end)

-- For Moblie
staminaButton.ImageButton.MouseButton1Down:Connect(function()
	sprint("Began")
end)

staminaButton.ImageButton.MouseButton1Up:Connect(function()
	sprint("Ended")
end)

-- Updating
game:GetService("RunService").RenderStepped:Connect(function()
	local humanoid = char:FindFirstChild("Humanoid")

	if stamina == 0 and isSprinting then
		sprint("Ended")
	end

	if isSprinting and humanoid.MoveDirection.Magnitude > 0 then
		stamina = stamina - 4 -- Run
	else
		stamina = stamina + 1.8 -- Rest
	end

	stamina = math.clamp(stamina,0,MaxStamina)
	staminaBar.BlueFrame.Size = UDim2.new(stamina/MaxStamina,0,1,0)
end)

here, sorry it took a while

2 Likes

U there? Not trying to rush You

Nvm Dident see respond my bad ima try it

My wifi cut out again greatttee but I appreciate u taking that much time just to help me thank you

1 Like

I’m not going able to test this until later cuz my bad wifi sucks

Trying it rn I will let u know

Weird I can still sprint while crawling

I copied ur script u gave me and I think my crawl script I messed up maybe anything wrong u see?

The crouching = true and the crouching = false under iscrawling is what u told me to do maybe I put it somewhere wrong