I made a script so that if a player presses C while theyre running they can slide. The problem is that if the player spams C then their walkspeed goes up like crazy. For refrence I want 32 to be the max speed they run when they arent sliding.
local UIS = game:GetService("UserInputService")
local char = script.Parent
local humanoid = char:WaitForChild("Humanoid")
local slideAnim = Instance.new("Animation")
local ca = tostring(script:WaitForChild("SlideAnim").AnimationId)
slideAnim.AnimationId = ca
local keybind = Enum.KeyCode.C
local canslide = true
UIS.InputBegan:Connect (function(input,gameprocessed)
if gameprocessed then return end
if not canslide then return end
if input.KeyCode == keybind and humanoid.WalkSpeed > 17 then
canslide = false
local playAnim = char.Humanoid:LoadAnimation(slideAnim)
wait()
playAnim:Play()
local snd = script.Slide
snd: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(0.1)
slide.Velocity *= 0.7
end
slide:Destroy()
playAnim:Stop()
humanoid.WalkSpeed = 32
wait(0.8)
canslide = true
print(humanoid.WalkSpeed)
end
end)