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 make an animation in a tool once you press a key?

I am making a war game and I need to make animations so that each tool has special keys to create animations.

For example, you can press T to throw stars once you equip the tool "Ninja Stars."

I know about this (click to play anim):

Tool = script.Parent local player = game.Players.LocalPlayer repeat wait() until player.Character ~= nil local hum = player.Character:WaitForChild("Humanoid")

local animation = Tool.ToolAnim 
 local AnimTrack = hum:LoadAnimation(animation) 

Tool.Activated:connect(function(mouse) 
mouse.Button1Down(connect(function()
AnimTrack:Play() 

end)


Tool.Deselected:connect(function() 
 AnimTrack:Stop() end)

But how do i put an key in it and play an animation so the player with the tool equipped plays it whenever he presses T?

1 answer

✓ Accepted answer

Just change the function that does AnimTrack:Play() to one like this:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.KeyDown:connect(function(key)
if key == "t" then
AnimTrack:Play()
end
end)

1 comment

0

Thanks for the answer!

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