What do I do if I want to make it so that if I clicked again it would play my second animation that shows the left arm punching
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local animation = script:WaitForChild("Animation1") enabled = true
mouse.Button1Down:Connect(function() if enabled then enabled = false
local animationTrack = player.Character.Humanoid:LoadAnimation(animation) animationTrack:Play() wait(1) enabled = true end
end)
Hey!
So I'm assuming your goal here is to have alternating punch animations. To do this, we'll just have a boolean (we'll call Alternate
) that switches every punch. On every punch, we'll just change Alternate
to its opposite.
Code shown below...
local Player = game:GetService("Players").LocalPlayer local Mouse = Player:GetMouse() local Animation1 = Player.Character.Humanoid:LoadAnimation(script:WaitForChild("Animation1")) -- Instead of loading them every punch, we can just do it once :) local Animation2 = Player.Character.Humanoid:LoadAnimation(script:WaitForChild("Animation2")) local Alternate = false -- This will be our alternating variable local Enabled = true -- This is actually called a debounce. Mouse.Button1Down:Connect (function() if Enabled then Enabled = false if Alternate then Animation1:Play() else Animation2:Play() end Alternate = not Alternate -- Changes to it's opposite value (true -> false / false -> true) wait(1) Enabled = true end end)
If this helped, please upvote it so I can get credit for taking the time to answer your question.