Hey guys, I was wondering why my animation is not playing. I followed the dev hub tutorial and it seems to not work.
-- create a idle animation
local Players = game:GetService("Players")
local function onCharacterAdded(character)
local humanoid = character:WaitForChild("Humanoid")
for _, playingTracks in pairs(humanoid:GetPlayinganimationTracks()) do
playingTracks:stop(0)
end
local animateScript = character:WaitForchild("Animate")
animateScript.idle.Animation1.AnimationId = "rbxassetid://3907655156"
-- assign weight 5 to anim 1
animateScript.idle.Animation1.Weight.Value = 5
animateScript.idle.Animation2.AnimationId = "rbxassetid://3907655156"
-- assign weight 5 to anim 2
animateScript.idle.Animation2.Weight.Value = 5
end
local function onPlayerAdded(player)
if player.Character then
onCharacterAdded(player.Character)
end
player.CharacterAdded:Connect(onCharacterAdded())
end
Players.PlayerAdded:Connect(onPlayerAdded)
My character just does the normal roblox idle animation.
It turns out that you weren’t trying to play an animation.
Redacted
The biggest issue is that you never loaded the animation and played it.
Here’s how you do it:
...
local LoadedAnimation = Humanoid:LoadAnimation(AnimationName)
LoadedAnimation:Play()
This is just an example, so just use this as loose guidelines for you follow. Don’t copy it verbatim.
Spoonfeeding
local function onCharacterAdded()
for _, playingTracks in pairs(humanoid:GetPlayinganimationTracks()) do
playingTracks:stop(0)
end
local animateScript = character:WaitForChild("Animate")
animateScript.idle.Animation1.AnimationId = "rbxassetid://3907655156"
-- assign weight 5 to anim 1
animateScript.idle.Animation1.Weight.Value = 5
animateScript.idle.Animation2.AnimationId = "rbxassetid://3907655156"
-- assign weight 5 to anim 2
animateScript.idle.Animation2.Weight.Value = 5
end
local function onPlayerAdded(player)
if player.Character then
onCharacterAdded(player.Character)
end
player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)
Yes, I agree with @mobyboyy
Make sure that the animations are uploaded onto your account, or a group you own, otherwise the animations will not load, also if the issue persists send a screenshot of f9 for any errors.
And yes that animation won’t play because you haven’t actually used :Play(), the rest is completely spot on by @mobyboyy
The script does not have to be a LocalScript it can run inside of a server-sided script. I have cleaned up your code for you, but you need to make sure that you capitalize things that are supposed to be capitalized.
For example, waitforchild() will not work, you must type it as WaitForChild()
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
local Humanoid = Character:WaitForChild("Humanoid")
for _,playingTracks in pairs(Humanoid:GetPlayingAnimationTracks()) do
playingTracks:Stop()
end
local animateScript = Character:WaitForChild("Animate")
animateScript.idle.Animation1.AnimationId = "rbxassetid://3907655156"
animateScript.idle.Animation1.Weight.Value = 5
animateScript.idle.Animation2.AnimationId = "rbxassetid://3907655156"
animateScript.idle.Animation2.Weight.Value = 5
end)
end)
yes I did, the game is in my group creations, does it have to be specifically under group creations for it to work? or can it be my own animations not made under the group?
So i had recently bought an a sword animation, It came with a sword, 2 sword swings animations, and an idle. I bought it for 700R. But it turns out that he had animation Id’s but the animations for which the Id’s come from are not in the file they game me. So I am asking about it now and they have not answered yet.
Assuming this is a LocalScript, there’s no need to have a character argument for function onCharacterAdded, as you can just refer to Player.Character already.
Yeah, plus in Studio (most of the time) it would not play the animation even if it is your animation so you would have to play it in the ACTUAL Roblox game.
For me I was trying to run an r6 animation on r15 character, make sure to go to settings => avatar and choose avater type either r6 or r15, if you want players to be able to choose their own body type then in the script where you play the animation add a little if-statement to check if the body type is r6 or r15 and play proper animation based on this
local Players = game:GetService("Players")
local function onCharacterAdded(character)
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
while not humanoid do
character.ChildAdded:Wait()
if not (character:FindFirstChildWhichIsA("Humanoid") == nil) then
humanoid = character:FindFirstChildWhichIsA("Humanoid")
end
end
for _, playingTracks in next, humanoid:GetPlayingAnimationTracks() do
playingTracks:stop(0)
end
local animateScript = character:WaitForchild("Animate")
animateScript.idle.Animation1.AnimationId = "rbxassetid://3907655156"
animateScript.idle.Animation1.Weight.Value = 5
animateScript.idle.Animation2.AnimationId = "rbxassetid://3907655156"
animateScript.idle.Animation2.Weight.Value = 5
local a1 = humanoid:LoadAnimation(script:WaitForChild("Idle"))
a1.Priority = Enum.AnimationPriority.Idle
a1:Play()
end
local function onPlayerAdded(player)
if player.Character then
onCharacterAdded(player.Character)
end
player.CharacterAdded:Connect(onCharacterAdded)
end
-- If it's for all players on the server
for a2, a3 in next, Players:GetPlayers() do
onPlayerAdded(a3)
end
-- If it's just for the client
onPlayerAdded(Players.LocalPlayer)