Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

1 comment

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

1 answer

✓ Accepted answer

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.

3 comments

0

Turns out this dosn't work, sorry. e.e

0

It is fine I figured out I had to set the animation's priority to action it wasn't the code at all.

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.