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.

01local Player = game.Players.LocalPlayer
02local Character = Player.Character or Player.CharacterAdded:wait()
03local Humanoid = Character:waitForChild("Humanoid")
04 
05local Animation = workspace:waitForChild("Animation")
06local AnimationTrack = Humanoid:LoadAnimation(Animation)
07 
08local UIS = game:getService("UserInputService")
09 
10UIS.InputBegan:connect(function(InputObject, gameProcessedEvent)
11    if not gameProcessedEvent then
12        if InputObject.KeyCode == Enum.KeyCode.P then
13            AnimationTrack:Play()
14        end
15    end
16end)
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?

01local Player = game.Players.LocalPlayer
02local Character = Player.Character or Player.CharacterAdded:wait()
03local Humanoid = Character:waitForChild("Humanoid")
04 
05local Animation = Instance.new("Animation") --creates new animation object
06Animation.AnimationId = "rbxassetid://Your Animation" --sets the id
07local AnimationTrack = Humanoid:LoadAnimation(Animation) -- loads the animation
08 
09local UIS = game:getService("UserInputService")
10 
11UIS.InputBegan:connect(function(InputObject, gameProcessedEvent)
12    if not gameProcessedEvent then
13        if InputObject.KeyCode == Enum.KeyCode.P then
14            AnimationTrack:Play() --it should work now
15        end
16    end
17end)

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