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 10 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):

01Tool = script.Parent local player = game.Players.LocalPlayer repeat wait() until player.Character ~= nil local hum = player.Character:WaitForChild("Humanoid")
02 
03local animation = Tool.ToolAnim
04 local AnimTrack = hum:LoadAnimation(animation)
05 
06Tool.Activated:connect(function(mouse)
07mouse.Button1Down(connect(function()
08AnimTrack:Play()
09 
10end)
11 
12 
13Tool.Deselected:connect(function()
14 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
10 years ago

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

1local player = game.Players.LocalPlayer
2local mouse = player:GetMouse()
3 
4mouse.KeyDown:connect(function(key)
5if key == "t" then
6AnimTrack:Play()
7end
8end)
0
Thanks for the answer! CowardlyArnold 20 — 10y
Ad

Answer this question