I was scripting knife throw script and when the tool unequipped it wont stop animation
01 | local ts = script.Parent:WaitForChild( "ThrowSystem" ) |
02 | tool = script.Parent |
03 | tossplaying = tool:WaitForChild( "TossPlaying" ) |
04 | Toss = script.Parent.Animations.Toss |
05 |
06 | tool.Equipped:Connect( function () |
07 | ts.Disabled = false |
08 | end ) |
09 | tool.Unequipped:Connect( function () |
10 | ts.Disabled = true |
11 | if tossplaying.Value ~ = true then |
12 | Toss:Stop() |
13 | tossplaying.Value = false |
14 | end |
15 | end ) |
09:50:51.793 - Stop is not a valid member of Animation
09:50:51.794 - Stack Begin
09:50:51.795 - Script 'Players.SunxLightz.Backpack.RamboKnife.DTS', Line 12
09:50:51.795 - Stack End
Stop is not a member of Animation. But it is a member of AnimationTracks. You don't actually call the :Stop()
method on the animation.
The humanoid has a :LoadAnimation(anim)
function which will load animation anim
on a humanoid.You can also use an AnimationController and do the same, but to keep this simple I'll use the humanoid.
01 | local client = game.Players.LocalPlayer -- If this is a local script, use LocalPlayer |
02 | local ts = script.Parent:WaitForChild( "ThrowSystem" ) |
03 | local tool = script.Parent |
04 | local tossplaying = tool:WaitForChild( "TossPlaying" ) |
05 | local Toss = client.Character.Humanoid:LoadAnimation(script.Parent.Animations.Toss) |
06 | -- Loading the animation |
07 |
08 | tool.Equipped:Connect( function () |
09 | ts.Disabled = false |
10 | end ) |
11 |
12 | tool.Unequipped:Connect( function () |
13 | ts.Disabled = true |
14 | if not tossplaying.Value then -- no need for ~= true, just 'not' |
15 | Toss:Stop() -- stopping the animation track |
16 | tossplaying.Value = false |
17 | end |
18 | end ) |
You need to stop animation with for i,v in pairs(humanoid:GetPlayingAnimationTracks()) do ... end
and use local VARIABLE = ...
here is a example:
01 | local player = game.Players.LocalPlayer |
02 | local char = player.Character or player.CharacterAdded:Wait() |
03 | local humanoid = char:WaitForChild( "Humanoid" ) |
04 |
05 | for i,v in pairs (humanoid:GetPlayingAnimationTracks()) do |
06 | if v.Name = = "ANIMATION_NAME" then |
07 | v:Stop() |
08 | break -- Stop this loop |
09 | end |
10 | end |
here is fixed script for:
01 | local player = game.Players.LocalPlayer |
02 | local char = player.Character or player.CharacterAdded:Wait() |
03 | local humanoid = char:WaitForChild( "Humanoid" ) |
04 |
05 | local ts = script.Parent:WaitForChild( "ThrowSystem" ) |
06 | local tool = script.Parent |
07 | local tossplaying = tool:WaitForChild( "TossPlaying" ) |
08 | local Toss = script.Parent.Animations.Toss |
09 |
10 | tool.Equipped:Connect( function () |
11 | ts.Disabled = false |
12 | end ) |
13 |
14 | tool.Unequipped:Connect( function () |
15 | ts.Disabled = true |
01 | local ts = script.Parent:WaitForChild( "ThrowSystem" ) |
02 | local tool = script.Parent |
03 | local tossplaying = tool:WaitForChild( "TossPlaying" ) |
04 | local Toss = script.Parent.Animations.Toss |
05 |
06 | tool.Equipped:Connect( function () |
07 | ts.Disabled = false |
08 | end ) |
09 |
10 | tool.Unequipped:Connect( function () |
11 | if tool.Parent.Parent:IsA( "Player" ) then |
12 | local char = tool.Parent.Parent.Character or tool.Parent.Parent.CharacterAdded:Wait() |
13 | local humanoid = char:WaitForChild( "Humanoid" ) |
14 | ts.Disabled = true |
15 | if tossplaying.Value ~ = true then |