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

Stop is not valid member of Animation?

Asked by 6 years ago
Edited 6 years ago

I was scripting knife throw script and when the tool unequipped it wont stop animation

01local ts = script.Parent:WaitForChild("ThrowSystem")
02tool = script.Parent
03tossplaying = tool:WaitForChild("TossPlaying")
04Toss = script.Parent.Animations.Toss
05 
06tool.Equipped:Connect(function()
07    ts.Disabled = false
08end)
09tool.Unequipped:Connect(function()
10    ts.Disabled = true
11    if tossplaying.Value ~= true then
12        Toss:Stop()
13        tossplaying.Value = false
14    end
15end)

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

2 answers

Log in to vote
0
Answered by 6 years ago

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.

01local client = game.Players.LocalPlayer-- If this is a local script, use LocalPlayer
02local ts = script.Parent:WaitForChild("ThrowSystem")
03local tool = script.Parent
04local tossplaying = tool:WaitForChild("TossPlaying")
05local Toss = client.Character.Humanoid:LoadAnimation(script.Parent.Animations.Toss)
06-- Loading the animation
07 
08tool.Equipped:Connect(function()
09    ts.Disabled = false
10end)
11 
12tool.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
18end)

Hopefully this answered your question, and if it did, then don't forget to hit that "Accept Answer" button. If you have any other questions, then feel free to leave them down in the comments.
Ad
Log in to vote
0
Answered by
yHasteeD 1819 Moderation Voter
6 years ago
Edited 6 years ago

You need to stop animation with for i,v in pairs(humanoid:GetPlayingAnimationTracks()) do ... end and use local VARIABLE = ...

here is a example:

01local player = game.Players.LocalPlayer
02local char = player.Character or player.CharacterAdded:Wait()
03local humanoid = char:WaitForChild("Humanoid")
04 
05for i,v in pairs(humanoid:GetPlayingAnimationTracks()) do
06    if v.Name == "ANIMATION_NAME" then
07        v:Stop()
08        break -- Stop this loop
09    end
10end

here is fixed script for:

LOCAL SCRIPT

01local player = game.Players.LocalPlayer
02local char = player.Character or player.CharacterAdded:Wait()
03local humanoid = char:WaitForChild("Humanoid")
04 
05local ts = script.Parent:WaitForChild("ThrowSystem")
06local tool = script.Parent
07local tossplaying = tool:WaitForChild("TossPlaying")
08local Toss = script.Parent.Animations.Toss
09 
10tool.Equipped:Connect(function()
11    ts.Disabled = false
12end)
13 
14tool.Unequipped:Connect(function()
15    ts.Disabled = true
View all 25 lines...

SERVER SCRIPT

01local ts = script.Parent:WaitForChild("ThrowSystem")
02local tool = script.Parent
03local tossplaying = tool:WaitForChild("TossPlaying")
04local Toss = script.Parent.Animations.Toss
05 
06tool.Equipped:Connect(function()
07    ts.Disabled = false
08end)
09 
10tool.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
View all 34 lines...

Hope it helped :)

Errors? tell-me on comments.


Solved your problems? put in title [SOLVED] or accept a answer
0
"workspace:WaitForChild(tool.Parent.Parent.Name)" is not the correct way to get a character. Use the Character property. User#24403 69 — 6y
0
changed yHasteeD 1819 — 6y

Answer this question