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
I tried what you said, but it won't play now?