--Services
local Player = game:GetService('Players').LocalPlayer
local RunService = game:GetService('RunService')
local InputService = game:GetService('UserInputService')
Player.CharacterAdded:Connect(function(Character)
local Humanoid = Character:FindFirstChild('Humanoid')
if not Humanoid then
return
end
local HumanoidRootPart = Character:FindFirstChild('HumanoidRootPart')
-- Walk Animation --
local Walk_Animation = Instance.new('Animation')
Walk_Animation.Name = 'Walk_Animation'
Walk_Animation.AnimationId = 'http://www.roblox.com/asset/?id=16970392360'
local Walk_Track = Humanoid:LoadAnimation(Walk_Animation)
-- Idle Animation --
local Idle_Animation = Instance.new('Animation')
Idle_Animation.Name = 'Idle_Animation'
Idle_Animation.AnimationId = 'http://www.roblox.com/asset/?id=16936362170'
local Idle_Track = Humanoid:LoadAnimation(Idle_Animation)
-- Run Animation --
local Run_Animation = Instance.new('Animation')
Run_Animation.Name = 'Run_Animation'
Run_Animation.AnimationId = 'http://www.roblox.com/asset/?id=16972097078'
local Run_Track = Humanoid:LoadAnimation(Run_Animation)
local Can_Walk = true
local function StopAnimation(except)
for _, track in ipairs(Humanoid:GetPlayingAnimationTracks()) do
if track ~= except and track.IsPlaying then
track:Stop()
end
end
end
local function Idle()
StopAnimation(Idle_Track)
if not Idle_Track.IsPlaying then
Idle_Track:Play()
end
end
local function Walking(Speed)
StopAnimation(Walk_Track)
if not Walk_Track.IsPlaying and Can_Walk == true then
Walk_Track:Play()
Humanoid.WalkSpeed = 10
end
end
local function Run(Speed)
StopAnimation(Run_Track)
if not Run_Track.IsPlaying then
Run_Track:Play()
Humanoid.WalkSpeed = 18
print('Running')
end
end
InputService.InputBegan:Connect(function(UserInput, gameProcessedEvent)
gameProcessedEvent = true
if UserInput.KeyCode == Enum.KeyCode.LeftShift then
Can_Walk = false
local Speed = Humanoid.MoveDirection.Magnitude
if Speed > 0 then
Run(Speed)
end
end
end)
InputService.InputEnded:Connect(function(UserInput, gameProcessedEvent)
gameProcessedEvent = true
if UserInput.KeyCode == Enum.KeyCode.LeftShift then
Can_Walk = true
end
end)
RunService.Heartbeat:Connect(function()
local Speed = Humanoid.MoveDirection.Magnitude
if Speed > 0 then
Walking(Speed)
end
if Speed == 0 then
Idle()
end
end)
end)
The run animation isnt playing and idk why, no errors.