Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My animation runner isn't working?

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)

2 comments

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.

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.

1 answer

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

2 comments

0

didnt work

0

Remove Player.CharacterAdded:wait() and just add repeat wait() until Character below the Character variable.

This discussion is preserved as it was. New answers, comments, and votes are closed.