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!
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
.
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)
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!