I made a weapon an I created an aiming animatin. I scripted everything and now if I press right click it plays the aiming animation. How would I make it to where if you are already aiming, and if you press mouse button 2 again it will stop? Does anybody know how to do this?
You can "pause" your animation using the AdjustSpeed
function on the AnimationTrack object. Wait until the button has been clicked again, and unpause :)
local plr = game.Players.LocalPlayer; --Player local char = plr.Character or plr.CharacterAdded:Wait(); --Character local human = char:WaitForChild("Humanoid"); --Humanoid local m = plr:GetMouse(); --Mouse local aiming = false; --Aiming variable local anim = Instance.new("Animation"); anim.AnimationId = "rbxassetid://" --Your id local stopAt = .3; --The `TimePosition` in which the anim should stop at m.Button2Down:Connect(function() if not aiming then aiming = true; local track = human:LoadAnimation(anim); track:Play(); --Play it repeat wait() until track.TimePosition >= stopAt track:AdjustSpeed(0); --Pause it m.Button2Down:Wait(); --Wait until clicked again track:Stop(); --Stop it wait(); aiming = false; end end)
Do something like this with a bool
local isplaying = false if isplaying == false then --animation stuff here isplaying = true --change it to false here if you want elseif isplaying == true then --[[animation]]:Stop() --anything else here