Hello,
Recently I’ve started working on a movement system that allows sprinting and sliding.
While working on adding animations to the sliding mechanic, I managed to get it somewhat working, the problem was when I noticed that whenever I sprinted, it acted as if I was sliding.
I haven’t tried much, as i don’t know where to start.
Thanks in advance.
Code:
local userInput = game:GetService("UserInputService")
local players = game:GetService("Players")
local sprintSpeed = 30
local walkSpeed = 16
local isrunning = false
local player = players.LocalPlayer
local function beginSprint(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.Keyboard then
local keycode = input.KeyCode
if keycode == Enum.KeyCode.LeftControl then
player.Character.Humanoid.WalkSpeed = sprintSpeed
if isrunning == false then isrunning = true
end
end
end
end
end
local function endSprint(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.Keyboard then
local keycode = input.KeyCode
if keycode == Enum.KeyCode.LeftControl then
player.Character.Humanoid.WalkSpeed = walkSpeed
if isrunning == true then isrunning = false
end
end
end
end
end
local function duringslide(input, gameProcessed)
if isrunning == true then
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.Keyboard then
local keycode = input.KeyCode
if keycode == Enum.KeyCode.C then
-- Import
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/Asset?ID=11309578902"
-- local variables
local animTrack = nil
local canPlay = true
if canPlay then
local pc = game.Players.LocalPlayer.Character
canPlay = false
animTrack = pc.Humanoid:LoadAnimation(animation)
animTrack:Play()
end
end
player.Character.Humanoid.WalkSpeed = player.Character.Humanoid.WalkSpeed * 1.5
wait(0.1) player.Character.Humanoid.WalkSpeed = player.Character.Humanoid.WalkSpeed - 2
wait(0.1) player.Character.Humanoid.WalkSpeed = player.Character.Humanoid.WalkSpeed - 3
wait(0.1) player.Character.Humanoid.WalkSpeed = player.Character.Humanoid.WalkSpeed - 4
wait(0.1) player.Character.Humanoid.WalkSpeed = player.Character.Humanoid.WalkSpeed - 6
wait(0.1) player.Character.Humanoid.WalkSpeed = player.Character.Humanoid.WalkSpeed - 9
end
end
end
end
local function endslide(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.Keyboard then
local keycode = input.KeyCode
if keycode == Enum.KeyCode.C then
player.Character.Humanoid.WalkSpeed = player.Character.Humanoid.walkspeed - 9
local animation = script:WaitForChild("Animation")
local animTrack = nil
local pc = game.Players.LocalPlayer.Character
animTrack = pc.Humanoid:LoadAnimation(animation)
animTrack.Stop()
end
end
end
end
userInput.InputBegan:Connect(duringslide)
userInput.InputEnded:Connect(endslide)
userInput.InputBegan:Connect(beginSprint)
userInput.InputEnded:Connect(endSprint)