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

How do you make an animation in a tool once you press a key?

Asked by 9 years ago

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

Log in to vote
1
Answered by
yumtaste 476 Moderation Voter
9 years ago

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)
0
Thanks for the answer! CowardlyArnold 20 — 9y
Ad

Answer this question