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

Can't play animations on a players humanoid?

Asked by 4 years ago

Playing animations has become an absolute nightmare now. Every time I try to create, load and play an animation on any local script, the animation doesn't run. Furthermore, when I use a script in the developer.roblox.com website it still doesn't work, but when I use the print function to test to see what is happening it shows that the animation has apparently played or something similar

developer.roblox.com script:

local Players = game:GetService("Players")
local character = Players.LocalPlayer.Character
if not character then
    character = Players.LocalPlayer.CharacterAdded:Wait()
end

local humanoid = character:WaitForChild("Humanoid")

-- Create new 'Animation' instance
local kickAnimation = Instance.new("Animation")
-- Set its 'AnimationId' to the corresponding animation asset ID
kickAnimation.AnimationId = "rbxassetid://3532148210"

-- Load animation onto the humanoid
local kickAnimationTrack = humanoid:LoadAnimation(kickAnimation)

-- Play animation track
print("brah")
kickAnimationTrack:Play()

-- Connect 'KeyframeReached' event to a specific named keyframe
kickAnimationTrack.KeyframeReached:Connect(function(keyframeName)
    print(keyframeName)
    if keyframeName == "KickEnd" then
        kickAnimationTrack:Play()
    end
end)

my code inside a tool (tool is inside starter character and Is In the character when the game plays)

script.Parent.Activated:Connect(function()
    print("Activated")
    local humanoid = script.Parent.Parent:FindFirstChildWhichIsA("Humanoid")
    local anim = script.Parent.Animation
    local animtrack = humanoid:LoadAnimation(anim)
    animtrack:Play()
end)

Any solutions? Others have told me that this code should work Thanks!

0
Go in game settings and make the avatar mode R6 Trading_Opportunity 191 — 4y
0
Thanks, this worked, from now on I am going to work on the game in R6. Is there a way of getting this to work in R15? Futuristic_Paladin 19 — 4y
0
I think that MAYBE you should make the anim already there. Instead of Instance.new() User#29913 36 — 4y
0
I will try that. Futuristic_Paladin 19 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Introduction

Hello, there friend!

I had the same problem like this one too.

In order to solve it, I suggest parenting the Animation to something, like inside the Tool.

Script

local Tool = script.Parent
local kickAnimation = Instance.new("Animation", Tool) --The comma indicates where the animation will be parented to, it's like a shortcut.
kickAnimation.Name = "KickAnimation"
kickAnimation.AnimationId = 'rbxassetid://123456789' --Your ID here

local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local character = player.Character or player.CharacterAdded:Wait()
while not character do
    character.AncestryChanged:Wait()
end


local Humanoid = character:WaitForChild('Humanoid')
local kickAnim = Humanoid:LoadAnimation(kickAnimation)

Tool.Activated:Connect(function()
    kickAnim:Play()
end)
Tool.Unequipped:Connect(function()
    kickAnim:Stop()
end)    

Conclusion

I believe the issue you have is mostly the parenting stuff, but it could be your definition of players and characters.

I hope I helped! Have a nice day, fella!

0
Thanks n Futuristic_Paladin 19 — 4y
0
You're welcome! Accept my answer down below from the comments to give you and me a little reputation! ;) Sensei_Developer 298 — 4y
Ad

Answer this question