Why is this script detecting player is running while he is not

Im making a script where if u press “key” u will slide only if u are running else u will crouch.

it work fine sometime. But sometime even if player is not running it will slide . and sometime even player is running player will crouch

here is script

local char = script.Parent
local uis = game:GetService("UserInputService")
local humanoid = char:WaitForChild("Humanoid")
local Humanoid = game:GetService("Players").LocalPlayer.Character:WaitForChild("Humanoid")
local slideAnim = Instance.new("Animation")
local canslide = true
local cas = game:GetService("ContextActionService")


slideAnim.AnimationId = "https://www.roblox.com/assets/?id=7557132162"

local function slidecrouch()
	local running= humanoid:GetState()
		if running == Enum.HumanoidStateType.Running then
			print("sliding")
			local playAnim = char.Humanoid:LoadAnimation(slideAnim)
			playAnim:Play()
			local slide = Instance.new("BodyVelocity")
			slide.MaxForce = Vector3.new(1,0,1) * 30000
			slide.Velocity = char.HumanoidRootPart.CFrame.lookVector * 100
			slide.Parent = char.HumanoidRootPart

			for count = 1, 8 do
				wait(.1)
				slide.Velocity *= .7
			end
			playAnim:Stop()
			slide:Destroy()
			canslide = true
		else 
			print("crouching")
			
		end
	
		end

	
end
cas:BindAction("slidingorcrouching",slidecrouch,true,"s")

Make sure you name your topic better. I would make something that just detects if the player is running because that looks like that’s your problem. Once you fix that reimplement it.

here is a script bit more easier to read

local char = script.Parent
local uis = game:GetService("UserInputService")
local humanoid = char:FindFirstChild("Humanoid")
local slideAnim = Instance.new("Animation")
local canslide = true
local cas = game:GetService("ContextActionService")


slideAnim.AnimationId = "https://www.roblox.com/assets/?id=7557132162"

local function slidecrouch()
	
		local running= humanoid:GetState()
		if running == Enum.HumanoidStateType.Running then
			print("sliding")
		else 
			print("crouching")
		end
		


end


cas:BindAction("slidingorcrouching",slidecrouch,true,"s")

Ok sorry for that. i will change it

I found out why it was happening . It was because of a roblox stupid bug which will occur if you donot add space while setting some value in boolean value . Really waste my time : (