Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can i disable my running script while im crouching in game?

Hello, I'm currently working on disabling the running script while im crouching. I've tried everything i know of but i cant do it.

Here are the scripts :

Running script

local Char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local Humanoid = Char:WaitForChild("Humanoid")
repeat wait() until game.Players.LocalPlayer

local m = game.Players.LocalPlayer:GetMouse()



m.KeyDown:connect(function(key)
	if key == "0" then --"Shift to run" 0 == shift
		print("Running")
		game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16 --change "25" to your speed you want
	end
end)

m.KeyUp:connect(function(key)
	if key == "0" then
		game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 10 --change "16" to your speed you want when you stop running
	end
end)

Crouching script

local Char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local Humanoid = Char:WaitForChild("Humanoid")
local UIS = game:GetService('UserInputService')
local IsCrawling = false
local CrouchDownAnimation = Humanoid:LoadAnimation(game.ReplicatedStorage.ClientAnimations:WaitForChild("CrouchDown"))
local CrouchingAnimation = Humanoid:LoadAnimation(game.ReplicatedStorage.ClientAnimations:WaitForChild("Crouching"))
local CrouchUpAnimation = Humanoid:LoadAnimation(game.ReplicatedStorage.ClientAnimations:WaitForChild("CrouchUp"))
local cancrawl = false

local topspeed = 12

Humanoid.Running:Connect(function(speed2)
	if speed2 > topspeed then 
		cancrawl = false
	elseif speed2 < topspeed then
		cancrawl = true


Humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
	if Humanoid.FloorMaterial == Enum.Material.Air then
		cancrawl = false
	elseif Humanoid.FloorMaterial ~= Enum.Material.Air then
		cancrawl = true

	end
end)







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

UIS.InputBegan:Connect(function(input,gameprocessed)
	if speed2 > topspeed then return end
	if gameprocessed then return end
	if not cancrawl then return end
	if input.KeyCode == Enum.KeyCode.C then
		if not IsCrawling then
			IsCrawling = true
			cancrawl = false
			
			CrouchDownAnimation:Play()
			wait(0.25)
			CrouchDownAnimation:Stop()
			CrouchingAnimation:Play()
			CrouchingAnimation:AdjustSpeed(0)
					Humanoid.WalkSpeed = 5
					game.StarterPlayer.CharacterJumpPower = 0
		end
	end
end)

UIS.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.C then
		if IsCrawling then
			IsCrawling = false
			cancrawl = true
			
			CrouchingAnimation:Stop()
			CrouchUpAnimation:Play()
			wait(0.25)
			CrouchUpAnimation:Stop()
					Humanoid.WalkSpeed = 10
					game.StarterPlayer.CharacterJumpPower = 0
		end
	end
		end)
		
	end
end)

1 answer

✓ Accepted answer

here at

UIS.InputBegan:Connect(function(input,gameprocessed)
    if speed2 > topspeed then return end
    if gameprocessed then return end
    if not cancrawl then return end
    if input.KeyCode == Enum.KeyCode.C then
        if not IsCrawling then
            IsCrawling = true
            cancrawl = false

            CrouchDownAnimation:Play()
            wait(0.25)
            CrouchDownAnimation:Stop()
            CrouchingAnimation:Play()
            CrouchingAnimation:AdjustSpeed(0)
                    Humanoid.WalkSpeed = 5
                    game.StarterPlayer.CharacterJumpPower = 0
        end
    end
end)

you can add ScriptYouwantToDisable.Disabled = true another solution that might be better is to just combine the script like this

local Char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local Humanoid = Char:WaitForChild("Humanoid")
local UIS = game:GetService('UserInputService')
local IsCrawling = false
local CrouchDownAnimation = Humanoid:LoadAnimation(game.ReplicatedStorage.ClientAnimations:WaitForChild("CrouchDown"))
local CrouchingAnimation = Humanoid:LoadAnimation(game.ReplicatedStorage.ClientAnimations:WaitForChild("Crouching"))
local CrouchUpAnimation = Humanoid:LoadAnimation(game.ReplicatedStorage.ClientAnimations:WaitForChild("CrouchUp"))
local cancrawl = false

local topspeed = 12

Humanoid.Running:Connect(function(speed2)
	if speed2 > topspeed then 
		cancrawl = false
	elseif speed2 < topspeed then
		cancrawl = true


		Humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
			if Humanoid.FloorMaterial == Enum.Material.Air then
				cancrawl = false
			elseif Humanoid.FloorMaterial ~= Enum.Material.Air then
				cancrawl = true

			end
		end)

		Humanoid.Running:Connect(function(speed)
			if speed > 0 then
				CrouchingAnimation:AdjustSpeed(1)
			else
				CrouchingAnimation:AdjustSpeed(0)
			end
		end)
		UIS.InputBegan:Connect(function(input,gameprocessed)
			if speed2 > topspeed then return end
			if gameprocessed then return end
			if input.KeyCode == Enum.KeyCode.C then
				if not IsCrawling then
					IsCrawling = true
					cancrawl = false
					print("Crawl")
					CrouchDownAnimation:Play()
					wait(0.25)
					CrouchDownAnimation:Stop()
					CrouchingAnimation:Play()
					CrouchingAnimation:AdjustSpeed(0)
					Humanoid.WalkSpeed = 5
					game.StarterPlayer.CharacterJumpPower = 0
				end
			elseif input.KeyCode == Enum.KeyCode.LeftShift and not IsCrawling then
				print("running")
				Humanoid.WalkSpeed = 25 --change "25" to your speed you want
			end
		end)
		UIS.InputEnded:Connect(function(input)
			if input.KeyCode == Enum.KeyCode.C then
				if IsCrawling then
					IsCrawling = false
					cancrawl = true
					print("not Crawl")
					CrouchingAnimation:Stop()
					CrouchUpAnimation:Play()
					wait(0.25)
					CrouchUpAnimation:Stop()
					Humanoid.WalkSpeed = 16
					game.StarterPlayer.CharacterJumpPower = 0
				end
			elseif input.KeyCode == Enum.KeyCode.LeftShift and not IsCrawling then -- can only run if its not IsCrawling
				print("Not running")
				Humanoid.WalkSpeed = 16 --change "16" to your speed you want when you stop running
			end
		end)

	end
end)

1 comment

0

Thanks i'll try this

This discussion is preserved as it was. New answers, comments, and votes are closed.