How would I go about stopping the KeyDown function?
So, I've been working on this script for a short while now, and with the help of another SH member, I've been able to get it working.
01 | lscript = script.Parent:WaitForChild( "LocalScript" ) |
03 | animation = lscript:WaitForChild( "ShunStart" ) |
04 | animation 1 = lscript:WaitForChild( "Salute" ) |
05 | animation 2 = lscript:WaitForChild( "RightDress" ) |
06 | animation 3 = lscript:WaitForChild( "AtEaseLoop" ) |
08 | local Player = game.Players.LocalPlayer |
09 | local Mouse = Player:GetMouse() |
10 | local animation = script.ShunStart |
11 | local animation 1 = script.Salute |
12 | local animation 2 = script.RightDress |
13 | local animation 3 = script.AtEaseLoop |
16 | script.Parent.Selected:connect( function () |
18 | Mouse.KeyDown:connect( function (key) |
20 | for _,v in pairs (Player.Character:FindFirstChild( "Humanoid" ):GetPlayingAnimationTracks()) do v:Stop( 0 ) end |
21 | animTrack = Player.Character:FindFirstChild( "Humanoid" ):LoadAnimation(animation) |
26 | Mouse.KeyDown:connect( function (key) |
28 | for _,v in pairs (Player.Character:FindFirstChild( "Humanoid" ):GetPlayingAnimationTracks()) do v:Stop( 0 ) end |
29 | animTrack = Player.Character:FindFirstChild( "Humanoid" ):LoadAnimation(animation 2 ) |
34 | Mouse.KeyDown:connect( function (key) |
36 | for _,v in pairs (Player.Character:FindFirstChild( "Humanoid" ):GetPlayingAnimationTracks()) do v:Stop( 0 ) end |
37 | animTrack = Player.Character:FindFirstChild( "Humanoid" ):LoadAnimation(animation 3 ) |
42 | Mouse.KeyDown:connect( function (key) |
44 | for _,v in pairs (Player.Character:FindFirstChild( "Humanoid" ):GetPlayingAnimationTracks()) do v:Stop( 0 ) end |
45 | animTrack = Player.Character:FindFirstChild( "Humanoid" ):LoadAnimation(animation 1 ) |
49 | animTrack = Player.Character:FindFirstChild( "Humanoid" ):LoadAnimation(animation) |
54 | Mouse.KeyDown:connect( function (key) |
55 | local Key = key:lower() |
57 | for _,v in pairs (Player.Character:FindFirstChild( "Humanoid" ):GetPlayingAnimationTracks()) do v:Stop( 0 ) end |
61 | script.Parent.Deselected:connect( function () |
62 | for _,v in pairs (Player.Character:FindFirstChild( "Humanoid" ):GetPlayingAnimationTracks()) do v:Stop( 0 ) return end |
The issue I seem to have is that, I tried to make it so that these animations would only play when the tool is selected, and that they'd stop being played once the tool is deselected.
So, for example; when the tool is selected, the animations will play when a key is pressed, but when the tool is not selected, the animations will not play when the keys are pressed.
It seems all that deselecting the tool does is stop the animations, which, whilst this is helpful, this really isn't what I wish to happen.
Again, help is much appreciated.