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

The animation won't play? Can anyone help? I don't understand animations.

Asked by 1 year ago

For some reason whenever I play the animation it just says "Play" is not a part of animation can anyone help?

local sword = script.Parent
local animation = Instance.new("Animation")
animation.Parent = workspace    
animation.AnimationId = "rbxassetid://10334388347"

sword.Activated:Connect(function()
    local plr = game.Players.LocalPlayer
    local character = plr.Character
    local humanoid = character:WaitForChild("Humanoid")
    local Anim =  humanoid:LoadAnimation(animation)
    animation:Play()
end)

2 answers

Log in to vote
0
Answered by
enes223 327 Moderation Voter
1 year ago

hey you! have you ever heard of enes? if you are in trouble, better call enes!

Ad
Log in to vote
0
Answered by 1 year ago
Edited 1 year ago

I recommend putting the animation INSIDE the script instead of making it while the game is running. Make sure it's like this: https://ibb.co/YRjQTd2 Also, you can put it in a local script, or server script. It will show to everyone even though it is a local script.

Instead of playing the animation itself, you need to play the loaded animation. The code should look like this. (You're making a sword, and to prevent it from being spammable I also made an cooldown.)

local sword = script.Parent
local animation = script:WaitForChild("Animation")
local debounce = false
local cooldownseconds = 1

sword.Activated:Connect(function()
    if debounce == false then
        debounce = true
        local plr = game.Players.LocalPlayer
        local character = plr.Character
        local humanoid = character:WaitForChild("Humanoid")
        local Anim =  humanoid:LoadAnimation(animation)
        Anim:Play()
        wait(cooldownseconds)
        debounce = false
    end
end)

On my old answer, you said it didn't work. I added your animation and inserted the ID. When I activated the sword, nothing happened. I made a test animation, and it played when I activated it. Your animation is probably empty, which is why it didn't work.

Answer this question