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

Why doesn't this script stop the animation when .Unequipped connects?

Asked by 5 years ago
local UIP = game:GetService("UserInputService")
animation1 = Instance.new("Animation", script.Parent)

script.Parent.Equipped:Connect(function()
    animation1.AnimationId = "rbxassetid://"..3358846513
    local animationtrack1 = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(animation1)
    animationtrack1:Play()
end)


script.Parent.Unequipped:Connect(function()
    animation1.AnimationId = "rbxassetid://"..3358846513
    local animationtrack1 = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(animation1)
    animationtrack1:Stop()
end)

When the tool is unequipped, the script is supposed to stop the animation from playing, but it just keeps looping. Why?

0
Maybe make sure that looped is false before it is stopped? Trollapse 89 — 5y

1 answer

Log in to vote
0
Answered by
DanzLua 2879 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

You want to create and use LoadAnimation outside of these events so both event functions has the animation.

Also you don't want to use the second parameter of Instance.new() because of this.

local UIP = game:GetService("UserInputService")

local animation1 = Instance.new("Animation")
animation1.AnimationId = "rbxassetid://"..3358846513
animation1.Parent=script.Parent

local animationtrack1 = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(animation1)

script.Parent.Equipped:Connect(function()
    animationtrack1:Play()
end)


script.Parent.Unequipped:Connect(function()
    animationtrack1:Stop()
end)
Ad

Answer this question