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

local ts = script.Parent:WaitForChild("ThrowSystem")
tool = script.Parent
tossplaying = tool:WaitForChild("TossPlaying")
Toss = script.Parent.Animations.Toss

tool.Equipped:Connect(function()
    ts.Disabled = false
end)
tool.Unequipped:Connect(function()
    ts.Disabled = true
    if tossplaying.Value ~= true then
        Toss:Stop()
        tossplaying.Value = false
    end
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

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.

local client = game.Players.LocalPlayer-- If this is a local script, use LocalPlayer
local ts = script.Parent:WaitForChild("ThrowSystem")
local tool = script.Parent
local tossplaying = tool:WaitForChild("TossPlaying")
local Toss = client.Character.Humanoid:LoadAnimation(script.Parent.Animations.Toss)
-- Loading the animation 

tool.Equipped:Connect(function()
    ts.Disabled = false
end)

tool.Unequipped:Connect(function()
    ts.Disabled = true
    if not tossplaying.Value then -- no need for ~= true, just 'not'
        Toss:Stop() -- stopping the animation track
        tossplaying.Value = false
    end
end)


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:

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")

for i,v in pairs(humanoid:GetPlayingAnimationTracks()) do 
    if v.Name == "ANIMATION_NAME" then
        v:Stop()
        break -- Stop this loop
    end
end

here is fixed script for:

LOCAL SCRIPT

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")

local ts = script.Parent:WaitForChild("ThrowSystem")
local tool = script.Parent
local tossplaying = tool:WaitForChild("TossPlaying")
local Toss = script.Parent.Animations.Toss

tool.Equipped:Connect(function()
    ts.Disabled = false
end)

tool.Unequipped:Connect(function()
    ts.Disabled = true
    if tossplaying.Value ~= true then
        for i,v in pairs(humanoid:GetPlayingAnimationTracks()) do 
            if v.Name == tostring(Toss.Name) then
                v:Stop()
                break -- Stop loop
            end
        end
        tossplaying.Value = false
    end
end)

SERVER SCRIPT

local ts = script.Parent:WaitForChild("ThrowSystem")
local tool = script.Parent
local tossplaying = tool:WaitForChild("TossPlaying")
local Toss = script.Parent.Animations.Toss

tool.Equipped:Connect(function()
    ts.Disabled = false
end)

tool.Unequipped:Connect(function()
    if tool.Parent.Parent:IsA("Player") then
        local char = tool.Parent.Parent.Character or tool.Parent.Parent.CharacterAdded:Wait()
        local humanoid = char:WaitForChild("Humanoid")
        ts.Disabled = true
        if tossplaying.Value ~= true then
            for i,v in pairs(humanoid:GetPlayingAnimationTracks()) do 
                if v.Name == tostring(Toss.Name) then
                    v:Stop()
                    break -- Stop loop
                end
            end
            tossplaying.Value = false
        end
    elseif tool.Parent:IsA("Model") and game.Players:GetPlayerFromCharacter(tool.Parent) then
        local char = tool.Parent
        local humanoid = char:WaitForChild("Humanoid")
        for i,v in pairs(humanoid:GetPlayingAnimationTracks()) do 
            if v.Name == tostring(Toss.Name) then
                v:Stop()
                break -- Stop loop
            end
        end
    end
end)

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