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
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
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
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
end
end
end
end)
Hope it helped :)
Errors? tell-me on comments.
Solved your problems? put in title [SOLVED] or accept a answer
2 comments
"workspace:WaitForChild(tool.Parent.Parent.Name)" is not the correct way to get a character. Use the Character property.
changed