I need help! I want the combo value reset to 1 (animation) when ever the player stops playing animations for more then 2 seconds.
-- Services
local plr = game:GetService("Players")
local mouse = plr.LocalPlayer:GetMouse()
local AnimFolder = game:GetService("ReplicatedStorage").Animations.Sword
local sword = script.Parent
-- Varibales
local char = plr.LocalPlayer.Character or plr.LocalPlayer.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local Animator = humanoid:WaitForChild("Animator")
local cooldown = true
local currTime = 0
char:SetAttribute("combo", 1)
-- table
local Animations = {
[1] = Animator:LoadAnimation(AnimFolder.atk1),
[2] = Animator:LoadAnimation(AnimFolder.atk2),
[3] = Animator:LoadAnimation(AnimFolder.atk3),
[4] = Animator:LoadAnimation(AnimFolder.atk4)
}
-- functions
local function cooldownReset()
cooldown = false
task.wait(.25)
cooldown = true
end
local function resetAnimation()
local combo = char:GetAttribute("combo")
print(tick() - currTime)
if combo > 4 then
char:SetAttribute("combo", 1)
cooldown = false
task.wait(2)
cooldown = true
end
end
local function playanims()
sword.Activated:Connect(function()
local combo = char:GetAttribute("combo")
if cooldown then
currTime = tick()
Animations[combo]:Play()
char:SetAttribute("combo", combo + 1)
cooldownReset()
resetAnimation()
end
end)
end
mouse.Button1Down:Connect(playanims)