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

*New* Why won't this Animation stop?

Asked by 10 years ago

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

Log in to vote
0
Answered by 10 years ago

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)

0
I tried what you said, but it won't play now? ScriptingHelpersALT 20 — 10y
Ad

Answer this question