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