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

after 2 seconds why is my animation not stopping?

Asked by 4 years ago

So I have a tool that when you click with it enabled, it sends the player who uses it, and the player they targets root parts to 2 parts I specified in a model. While they are sent there, a animation is supposed to play, and then after 2 seconds their rootparts get moved back to the map. The animation plays fine, but after 2 seconds it doesnt stop and it continues playing, heres the script:

local Tool = script.Parent.Parent.Parent.Parent

script.Parent.OnServerEvent:Connect(function(plr, Mouse)
    local rng = math.random(2,2)
    print(rng)
    if rng == 2 then 
        print("working")
        local Detect = Instance.new("Part",workspace)
        Detect.Transparency = 1
        Detect.Anchored = true
        Detect.Size = Vector3.new(50,50,50)
        Detect.CanCollide = true
        Detect.CFrame = plr.Character.HumanoidRootPart.CFrame

        Detect.Touched:Connect(function(hit, Player)
            print("test")

            local player = game.Players:GetPlayerFromCharacter(hit.Parent) 
            if player then
                print("testing")
                local AttackPart = game.Workspace.TsukuyomiModel.AttackerPart
                local EnemyPart = game.Workspace.TsukuyomiModel.EnemyTsukuPart
                plr.Character:WaitForChild("HumanoidRootPart").CFrame = AttackPart.CFrame
                player.Character:WaitForChild("HumanoidRootPart").CFrame = EnemyPart.CFrame
                player.Character.HumanoidRootPart.Anchored = true
                player.Character.UpperTorso.CFrame = CFrame.new(-67.91, -224.94, 202.345) * CFrame.fromEulerAnglesXYZ(0,89.5,0)
                local animationTrack = player.Character.Humanoid:LoadAnimation(script.Animations.EnemyAnim)
                animationTrack:Play()
                player.Character.Humanoid:TakeDamage(1)


            end
            wait(2.5)
            local returnpart = game.Workspace.returnpart
            print("testing")
            player.Character.HumanoidRootPart.Anchored = false
            plr.Character:WaitForChild("HumanoidRootPart").CFrame = returnpart.CFrame
            player.Character:WaitForChild("HumanoidRootPart").CFrame = returnpart.CFrame
            local animationTrack = player.Character.Humanoid:LoadAnimation(script.Animations.EnemyAnim)
            animationTrack:Stop()
        end)
    end
end)

0
It could be that you looped the animation while making it. Try checking that Ghost40Z 118 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

The point(i hope) is that you creating a new local for animation, so you stop new animation, not your old

just create a local animation out of an if statement, play on touch and the stopp after the 2.5 seconds.

local animationTrack = player.Character.Humanoid:LoadAnimation(script.Animations.EnemyAnim)
--your if statement
animationTrack:Play()
end

wait(2.5)
animationTrack:Stop()
Ad

Answer this question