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

How do you play an animation when a tool is activated?

Asked by 5 years ago

I am trying to make an animation play when a tool is activated, but I don't know how. For some weird reason, if I equip the tool, activate it, and unequip it super fast, it shows part of the animation playing and it won't print the error message, so I think it is trying to play, but I can't see it because because the tool being equipped won't allow it to play. Can someone tell me how to play an animation when a tool is activated? I want to make a throwable pizza for a food fighting game, and I need to play a throwing animation right when the tool is activated to make my character move the tool in a way that it looks like I am throwing it. Another thing - is it possible to do this? Do I need to change my scripts?

    wait()
    local CanEmote = true
    local Player = game.Players.LocalPlayer
    local character = Player.Character or Player.CharacterAdded:Wait()
    local Humanoid = character.Humanoid
    local Animation = Humanoid:LoadAnimation(script.Throw)

    script.Parent.Activated:Connect(function()
      if CanEmote then
        Animation:Play()
        CanEmote = false
        wait(1)
        CanEmote = true

      else print("An Error Occured")
      end
    end)

0
Could you open the developer console, when you run in game, and see what the error is from there? Thank you very much. xx BunicornBoy 17 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

After having a discussion with you, I have came up with this script:

-- script doesn't work.

Edit: I think what you need to do is detect if it's selected and when the mouse button clicked, then set it to active.

Tell me if this works. Thanks xx.

0
Turns out this dosn't work, sorry. e.e BunicornBoy 17 — 5y
0
It is fine I figured out I had to set the animation's priority to action it wasn't the code at all. RetroGalacticGamer 331 — 5y
0
I will accept your answer so this question won't be answered since I figured it out so we can get reputation for free! RetroGalacticGamer 331 — 5y
Ad

Answer this question