so im making a game and i want it that when i click the first animation will play and when i click again the second one will play then if i click again it will play the first one again, you get it
tool/animation script
Remotes:WaitForChild("SwordSlash").OnServerInvoke = function(player,tool,SAnimation) local char = player.Character local Hm = char:WaitForChild("Humanoid") local rp = char:WaitForChild("HumanoidRootPart") local HitBox = tool:WaitForChild("HitBox") local CanAttack = tool:WaitForChild("CanAttack") local SwordOut = tool:WaitForChild("SwordOut") local CoolDown = 0.5 local AttackName = "Katana Slash"--You can Rename this one local AttackDamage = 10 local Length = 1--How long it will last local Speed = 20--How fast the move is local randomSlash = math.random(1, 2) if randomSlash == 1 then SAnimation.AnimationId = "rbxassetid://4874743902" --, rbxassetid://4871586095 local Track = Hm:LoadAnimation(SAnimation) if SwordOut.Value and CanAttack.Value and Track.Length ~= 0 then CanAttack.Value = false local Bv = Instance.new("BodyVelocity") Bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge) Bv.Velocity = rp.CFrame.LookVector * 5 Track:Play() wait(0) GlowSword1(tool,true) Bv.Parent = rp Debris:AddItem(Bv,0.7) local ATouch = HitBox.Touched:Connect(function(hit) DamageTarget(char,hit,AttackName,AttackDamage,0.2) end) wait(0.3) ATouch:Disconnect() GlowSword1(tool,false) CanAttack.Value = true wait(CoolDown) end elseif randomSlash == 2 then SAnimation.AnimationId = "rbxassetid://4871586095" --, rbxassetid://4871586095 local Track = Hm:LoadAnimation(SAnimation) if SwordOut.Value and CanAttack.Value and Track.Length ~= 0 then CanAttack.Value = false local Bv = Instance.new("BodyVelocity") Bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge) Bv.Velocity = rp.CFrame.LookVector * 5 Track:Play() wait(0) GlowSword1(tool,true) Bv.Parent = rp Debris:AddItem(Bv,0.7) local ATouch = HitBox.Touched:Connect(function(hit) DamageTarget(char,hit,AttackName,AttackDamage,0.2) end) wait(0.3) ATouch:Disconnect() GlowSword1(tool,false) CanAttack.Value = true wait(CoolDown) end return false end
heres the click script ignore the other ones it should be named ****Attack
local UserInputService = game:GetService("UserInputService") local tool = script.Parent local SwordAnimation = tool:WaitForChild("SwordAnimation") local Remotes = tool.Remotes local CantAttack = tool:WaitForChild("CanAttack") local SwordOut = tool:WaitForChild("SwordOut") local Attack = false local Attack_1 = false local Attack_2 = false local Attack_3 = false local Attack_4 = false tool.Equipped:Connect(function() Remotes:WaitForChild("SwordEqRE"):FireServer(tool,true) end) tool.Unequipped:Connect(function() Remotes:WaitForChild("SwordEqRE"):FireServer(tool,false) end) UserInputService.InputBegan:Connect(function(input,Processed) if not Processed then if input.UserInputType == Enum.UserInputType.MouseButton1 and SwordOut.Value and CantAttack.Value and not Attack then spawn(function() Attack = true Attack = Remotes:WaitForChild("SwordSlash"):InvokeServer(tool,SwordAnimation) end) elseif input.KeyCode == Enum.KeyCode.Q and SwordOut.Value and CantAttack.Value and not Attack_1 then spawn(function() Attack_1 = true Attack_1 = Remotes:WaitForChild("WaterWheelRF"):InvokeServer(tool,SwordAnimation) end) elseif input.KeyCode == Enum.KeyCode.E and SwordOut.Value and CantAttack.Value and not Attack_2 then spawn(function() Attack_2 = true Attack_2 = Remotes:WaitForChild("WaterfallBasinRF"):InvokeServer(tool,SwordAnimation) end) elseif input.KeyCode == Enum.KeyCode.R and SwordOut.Value and CantAttack.Value and not Attack_3 then spawn(function() Attack_3 = true Attack_3 = Remotes:WaitForChild("ConstantFluxRF"):InvokeServer(tool,SwordAnimation) end) elseif input.KeyCode == Enum.KeyCode.F and SwordOut.Value and CantAttack.Value and not Attack_4 then spawn(function() Attack_4 = true Attack_4 = Remotes:WaitForChild("DeadCalmRF"):InvokeServer(tool,SwordAnimation) end) end end end)
If you'd like to make something alternate between two options, you could use a boolean value. It could look something like this:
local FirstAnimation = true function PlayAnimation() if FirstAnimation then FirstAnimationTrack:Play() else SecondAnimationTrack:Play() end FirstAnimation = not FirstAnimation end
If you implement something like this into where you play animations, every time you play an animation, it will switch, because FirstAnimation alternates between true and false.