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")