Small Typo with 'Player'
'Player' should be 'Players', also no need for the conditional check on MouseButton1Click, and also the reason this is occurring is because you're stopping it each time you play it.
Try using some debounces!
Also, we don't want to keep loading in new Instances to the player each time they click the button! Let's try something as so:
Hint, sometimes using functions to organize things can help a lot.
Here's a way I would organize it to make it neater for future scripts as-well.
local plr = game.Players.LocalPlayer
local chr = plr.Character or plr.CharacterAdded:wait()
local Animation;
local animTrack;
local playing = false;
function newAnimation(Id)
Animation = Instance.new("Animation")
animTrack = chr["Humanoid"]:LoadAnimation(Animation)
Animation.AnimationId = "http://www.roblox.com/asset?id=" .. Id
end
function hasAnimation(Id)
if chr:FindFirstChild("Animation") and chr["Animation"].AnimationId == "http://www.roblox.com/asset?id="..Id then
return true
end
return false
end
function stop()
animTrack:Stop()
playing = false;
end
function play()
animTrack:Play()
playing = true;
end
script.Parent.MouseButton1Down:connect(function()
print("Clicked!")
if not hasAnimation(234539352) then
newAnimation(234539352)
end
if not playing then
play()
elseif playing then
stop()
end
end)
Code Above Is Untested
8 comments
It didn't work, there was nothing in the output.
Is this in a local-script?
Ah, no. I'll change it to a local script.
Remember, whenever you see 'LocalPlayer', that means that it has to be a local-script for it to work.
It doesn't work, still. :/
Any output?
There is no output.
Any idea of what to do?