Trying to make a animation run script

I’ve been trying to make a script lately, and it makes no sense at all why its not working, I just need a bit of help ;q ```local UIS = game:GetService(‘UserInputService’)
local Player = game.Players.LocalPlayer
local Character = Player.Character

UIS.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
Character.Humanoid.WalkSpeed = 35
local Anim = Instance.new(‘Animation’)
Anim.AnimationId = ‘rbxassetid://6324141335’
PlayAnim = Character.Humanoid:LoadAnimation(Anim)
PlayAnim:Play()
end
end)

UIS.InputEnded:connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
Character.Humanoid.WalkSpeed = 16
PlayAnim:Stop()
end
end)

1 Like

Are you sure your animation is working? Have you tried debugging your code, adding in prints, etc? Anyways, just a sidenote humanoid:LoadAnimation is deprecated , so you should load animation on the animator instead. You can create an animator by using Instance.new(“Animator”) or reference it from the humanoid: local animator = humanoid:FindFirstChildOfClass("Animator"). You also don’t need to load your animation within your UserInput events or create an animation there as well. I believe doing so means you’re creating a new animation and loading it each time the input is fired, which may cause an issue.

local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")

local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://6324141335"

if Humanoid then
    local Animator = Humanoid:FindFirstChildOfClass("Animator") -- Get the Animator
    if Animator then
        PlayAnim = Animator:LoadAnimation(Animation) -- Load the animation   
    end
end

UIS.InputBegan:connect(function(input)
    if input.KeyCode == Enum.KeyCode.LeftShift then
       PlayAnim:Play()
       Humanoid.WalkSpeed = 35
    end
end)

UIS.InputEnded:connect(function(input)
    if input.KeyCode == Enum.KeyCode.LeftShift then
       PlayAnim:Stop()
       Humanoid.WalkSpeed = 16
    end
end)
1 Like

I recommend going to the tool shop and getting a ninja animation or loading your game and getting the Animate script out of your char copy & Paste into workspace and Edit the run script.

1 Like