My animation doesn’t play and I’m using a local script. This is the script:
script.Parent.MouseButton1Click:Connect(function()
local Anim = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Animation)
Anim:Play()
print("playedddd")
end)
There were no errors and it printed the ‘playedddd’ text. I tried this on another local script, it works but I’m not sure why suddenly it doesn’t work.
So I tried to do that, I used the code from the developer website article but what happened is the ‘got here’ was printed but ‘ran’ wasn’t printed. No errors either. It still doesn’t work.
script.Parent.MouseButton1Click:Connect(function()
--[[ local Anim = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Animation)
Anim:Play()
print("playedddd")--]]
print"got here"
local character = game.Players.LocalPlayer.Character
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
-- need to use animation object for server access
local animator = humanoid:FindFirstChildOfClass("Animator")
if animator then
local animationTrack = animator:LoadAnimation(script.Animation)
animationTrack:Play()
return animationTrack
end
end
print"ran"
end)
I think it’s because Character, Humanoid, or Animator hasn’t loaded yet.
Use this:
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
script.Parent.MouseButton1Click:Connect(function()
print"got here"
animator:LoadAnimation(script.Animation):Play()
print"ran"
end)
If it doesn’t work, would you like to find the character in your workspace?
local Player = game.Players.LocalPlayer
local Char = game.Workspace:WaitForChild(Player.Name)
local Humanoid = Char:WaitForChild("Humanoid")
local Animation = script:WaitForChild("Animation")
script.Parent.MouseButton1Click:Connect(function()
local Anim = Humanoid:LoadAnimation(Animation)
Anim:Play()
end)
I tested it. If this really doesn’t work, I think there’s a problem with animation.
And make sure the animation belongs to your account.
Thank you.
The animation does belong to my account and it has worked before, like I said, but in a different game (in fact it was just empty baseplate). That’s the code I used as well.
What can I say, you’re right!! I didn’t even know about the ownership part and didn’t notice I uploaded it as my own when instead should’ve uploaded it to the group. Thanks!