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

*New* Why won't this Animation stop?

Now it only plays, it won't Stop.

Enabled = false
script.Parent.MouseButton1Click:connect(function()
	if Enabled == false then
		Enabled = true
local Humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
local example = Humanoid:LoadAnimation(script.Parent.Animation)
example:Play()
	else
		if Enabled == true then
			Enabled = false
		example:Stop()
	end
	end
	end)

1 answer

You define a new local variable called example inside the if part. This means that the variable example does not exist outside of the if then... part.

The best way to fix this is to define example right at the start:

Enabled = false
local example = Humanoid:LoadAnimation(script.Parent.Animation)
script.Parent.MouseButton1Click:connect(function()
    if Enabled == false then
        Enabled = true
	local Humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
	example:Play()
    else
        if Enabled == true then
            Enabled = false
        example:Stop()
    end
    end
    end)

Another way to fix this is to remove the "local" before the example like this:

example = Humanoid:LoadAnimation(script.Parent.Animation)

or you could just redefine example (but this isn't a very good way of doing things)

example:Play()
    else
	local example = Humanoid:LoadAnimation(script.Parent.Animation)
        if Enabled == true then
            Enabled = false
        example:Stop()
    end
    end
    end)

1 comment

0

I tried what you said, but it won't play now?

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