Making a sword combat system, and i dont know how to make mutiple animations on a click.
What the clicks do
First Click: Plays a animation
Second Click: Plays the second animation
Third Click: Plays the third animation
Fourth Click: Plays the fourth animation
Please keep in mind i am NOT asking for free code.
You could technically use a number variable that adds up by one per click. Depending on the number, you play a specific animation. When it reaches the number 4, you can just set it to it’s starting number.
I will just say what @Downrest means: just an example
local number = 0
button.MouseButton1Click:Connect(function()
number = number + 1
if number == 1 then
animation1:Play()
elseif number == 2 then
animation2:Play()
elseif number == 2 then
animation3:Play()
elseif number == 4 then
animation4:Play()
number = 0 -- Restarts from the beginning.
end
end)
If you want more easier but complex measures:
local number = 0
local audioDictionary = {
[1] = 0, - audio ID of anim 1
[2] = 0, - audio ID of anim 2
[3] = 0, - audio ID of anim 3
[4] = 0, - audio ID of anim 4
}
button.MouseButton1Click:Connect(function()
number = number + 1
anim.AnimationId = "rbxassetid://"..audioDictionary[number]
anim:Play()
if number == 4 then
number = 0
end
end)
Oh so you want to click it on a tool. That’s easy, just do this:
local number = 0
script.Parent.Activated:Connect(function()
number = number + 1
if number == 1 then
script.A1:Play()
elseif number == 2 then
script.A2:Play()
elseif number == 2 then
script.A3:Play()
elseif number == 4 then
script.A4:Play()
number = 0 -- Restarts from the beginning.
end
end)
I saw that you were using my second method, but that only works when you have 1 animation.
I’m feeling like this statement was false, but to load an animation:
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local loadAnim = character.Humanoid.Animator:LoadAnimation(ANIMNAME)
loadAnim:Play()
--// Services
local Players = game:GetService("Players")
--// Player Instances
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
--// Tool
local Tool = -- Define Tool Here
--// Tables
local Animations = { -- You can add more and it will always play the next animation
124124124, -- 1
124124124, -- 2
124124124, -- 3
124124124, -- 4
}
local loadedAnimations = {}
--// Functions
local function loadAllAnimations()
local Humanoid = Character:FindFirstChild("Humanoid")
if not Humanoid then return warn("No humanoid") end
for Index, ID in ipairs(Animations) do
local animationInstance = Instance.new("Animation")
animationInstance.AnimationId = "rbxassetid://"..ID
local loadedAnimation = Humanoid:LoadAnimation(animationInstance)
table.insert(loadAnimations, loadedAnimation)
end
end)
loadAllAnimations()
--// Connection
local timesPressed = 1
Tool.Activated:Connect(function()
loadedAnimation[timesPressed]:Play()
timesPressed += 1
if timesPressed >= #Animations then timesPressed = 0 end
end)
Hope this helps, just wrote this so no clue if it will work but you can try it out. Though make sure it fits your game by changing tool location and animations IDs