Skip to content

Instantly share code, notes, and snippets.

@Ethan-Rivas
Last active March 28, 2017 14:54
Show Gist options
  • Save Ethan-Rivas/1a235f77c9ea5c5186336402ce125279 to your computer and use it in GitHub Desktop.
Save Ethan-Rivas/1a235f77c9ea5c5186336402ce125279 to your computer and use it in GitHub Desktop.
LShift to Run with Animation - Roblox
--// Services
local Players = game:GetService("Players")
local UIS = game:GetService("UserInputService")
--// Local Variables
local player = Players.LocalPlayer
local animation = Instance.new("Animation")
local trackAnimation = nil
--// Setters
animation.AnimationId = "http://www.roblox.com/Asset?ID=707925354"
--// Function
function playAnimation(Anim)
trackAnimation = player.Character.Humanoid:LoadAnimation(animation)
trackAnimation:Play()
trackAnimation:AdjustSpeed(4)
--// Debug speed
player.Character.Humanoid.Running:connect(function(speed)
if speed > 0 then
print("Speed: " .. speed)
else
print("Player has stopped")
end
end)
end
--// Input Began
UIS.InputBegan:Connect(function(input)
if(input.KeyCode == Enum.KeyCode.LeftShift)then
playAnimation(animation)
while(player.Character.Humanoid.WalkSpeed < 40)do
player.Character.Humanoid.WalkSpeed = player.Character.Humanoid.WalkSpeed + 5
wait(0.5)
end
end
end)
--// Input Ended
UIS.InputEnded:Connect(function(input)
if(input.KeyCode == Enum.KeyCode.LeftShift)then
while(player.Character.Humanoid.WalkSpeed > 20)do
player.Character.Humanoid.WalkSpeed = player.Character.Humanoid.WalkSpeed - 5
wait(0.2)
end
trackAnimation:Stop()
end
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment