Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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?

1 comment

0

Maybe make sure that looped is false before it is stopped?

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.