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

My animation runner isn't working?

Asked by
Relatch 550 Moderation Voter
9 years ago

Basically, when a player presses p I want it to run a animation. When I press p, it doesn't run the animation. The animation is just a simple punching animaton.

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Humanoid = Character:waitForChild("Humanoid")

local Animation = workspace:waitForChild("Animation")
local AnimationTrack = Humanoid:LoadAnimation(Animation)

local UIS = game:getService("UserInputService")

UIS.InputBegan:connect(function(InputObject, gameProcessedEvent)
    if not gameProcessedEvent then
        if InputObject.KeyCode == Enum.KeyCode.P then
            AnimationTrack:Play()
        end
    end
end)
3
Try to redirect your animation as the child of your script. Also, add "print" functions a line after every "WaitForChild" methods and make sure that they're printed in the output. If one line isn't printed, then that means the object before that line is nonexistent. Redbullusa 1580 — 9y
0
^ As mentioned above, put print functions on every line to see where the script is stopping. It may be a little obnoxious at first, but you'll find the problem. Validark 1580 — 9y

1 answer

Log in to vote
5
Answered by
Hero_ic 502 Moderation Voter
9 years ago

Maybe instead of getting an animation object in the workspace why not instance a new one and set the animation id in the script itself?

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Humanoid = Character:waitForChild("Humanoid")

local Animation = Instance.new("Animation") --creates new animation object
Animation.AnimationId = "rbxassetid://Your Animation" --sets the id
local AnimationTrack = Humanoid:LoadAnimation(Animation) -- loads the animation

local UIS = game:getService("UserInputService")

UIS.InputBegan:connect(function(InputObject, gameProcessedEvent)
    if not gameProcessedEvent then
        if InputObject.KeyCode == Enum.KeyCode.P then
            AnimationTrack:Play() --it should work now
        end
    end
end)

If it works please accept and thanks for asking -_^ ~KiHeros

0
didnt work Relatch 550 — 9y
0
Remove Player.CharacterAdded:wait() and just add repeat wait() until Character below the Character variable. Spongocardo 1991 — 9y
Ad

Answer this question