anim = 0 -- if tool is equipped
script.Parent.Equipped:connect(function()
anim = 1
script.Parent.rright.Value = true -- checks if it should play right animation
script.Parent.lleft.Value = false -- checks if it should play left animation
end)
script.Parent.Unequipped:connect(function()
anim = 0
script.Parent.rright.Value = false
script.Parent.lleft.Value = false
end)
game.Players.LocalPlayer:GetMouse().Button1Down:connect(function()
if anim == 1 then
if script.Parent.rright.Value == true then
script.Parent.rright.Value = false
script.Parent.lleft.Value = true
game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.right):Play()
end
end
if anim == 1 then
if script.Parent.lleft.Value == true then
script.Parent.lleft.Value = false
script.Parent.rright.Value = true
game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.left):Play()
end
end
end)
--what i want this script to do is when you click you play the right animation and then if you click again you play the left animation, what it does now is it just plays the left animation everytime you click.
What is wrong with this animation script I made for my tool?
1 answer
I answered your question before but misread it, so I hope the answer I give is actually correct this time.
I tested your script and the problem is that it plays both the animations at the same time. Since the left animation is the last animation line, it'll look like it plays that only, but in reality it also plays the right animation but really quickly.
The reason it does this is because you have two separate conditional statements (if-then). The first one turns the "lleft" value true so when the script moves on to the next statement, "lleft" is true, so it'll instantly play the other animation.
Here's a modified version of your script. I tested it so it should work :
--Animations are in script
anim = 0
right = false
left = false
script.Parent.Equipped:Connect(function()
anim = 1
right = true
left = false
end)
script.Parent.Unequipped:Connect(function()
anim = 0
right = false
left = false
end)
game.Players.LocalPlayer:GetMouse().Button1Down:Connect(function()
if anim == 1 then
if right == true then
right = false
left = true
game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Right):Play()
else
right = true
left = false
game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Left):Play()
end
end
end)
I combined the two conditional statements into one statement with an "else" in it. That means when "right" is not true, it'll do the left animation instead, otherwise it's vice versa.
Also you don't need value instances for this. Just use variables, it's a lot more simple.
1 comment
Thank you very much! I've been trying to fix this for a long time and I really appreciate you teaching me!
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
Does the animation play?
you can try making the bool value as a Instance instead of making as a variable
The animation plays but only the left animation.
and the exact same thing happens skyofindia