Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How would I make the animation work for my sprint script?

Asked by
FBS_8 25
4 years ago
Edited 4 years ago

I have tried to add an animation when sprinting to my script but it doesn't seem to work, the output says: "Stop is not a valid member of animation"

local anim = script.RunAnim
repeat wait() until script.Parent.Name == "Backpack"
script.KeyDown.OnServerEvent:Connect(function(asd,yo)
    if yo == "0" then
        script.Parent.Parent.Character.Humanoid.WalkSpeed = 20
        anim:Play()
    end
end)
script.KeyUp.OnServerEvent:Connect(function(asd,yo)
    if yo == "0" then
        script.Parent.Parent.Character.Humanoid.WalkSpeed = 13
        anim:Stop()
    end
end)

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Okay, a lot of mistakes but I'll help you out.

Make a local script (Client script), put inside the animation (named RunAnim),put it in the starter pack and write the following:

local UIS = game:GetService("UserInputService")
local p = game:GetService("Players").LocalPlayer
local c  = p.Character or p.CharacterAdded:Wait()
local anim = script.RunAnim
local RunAnimation = c:WaitForChild("Humanoid"):LoadAnimation(anim)
UIS.InputBegan:Connect(function(i,a)
    if not a then
        if i.KeyCode == Enum.KeyCode.LeftShift then
            c:WaitForChild("Humanoid").WalkSpeed = 20
            RunAnimation:Play()
        end
    end
end)

UIS.InputEnded:Connect(function(i,a)
    if not a then
        if i.KeyCode == Enum.KeyCode.LeftShift then
            c:WaitForChild("Humanoid").WalkSpeed = 13
            RunAnimation:Stop()
        end
    end
end)
0
Works thx FBS_8 25 — 4y
Ad

Answer this question