I'm trying to make a combo system that resets to the initial animation it started with if the player remains idle after attacking. It would go to 1,2,3,4,5 then reset back to 1; but if you were idle and stopped at 3 it would go 1,2,3 wait and back to 1.
But the local-script I have right now doesn't reset it at all, it just keeps going with the regular cycle of 1,2,3,4,5
local uis = game:GetService("UserInputService") local repstorage = game:GetService('ReplicatedStorage') local events = repstorage:FindFirstChild("Events") local modules = repstorage:FindFirstChild("Modules") local player = game.Players.LocalPlayer local char = player.Character or player.CharacterAdded:Wait() repeat wait() until player:HasAppearanceLoaded() local current = 1 local cooldown = false local startTime = tick() local maxTime = 1.5 local animTable = { "rbxassetid://04540124455", "rbxassetid://04540153886", "rbxassetid://04540429673", "rbxassetid://4540628785" , "rbxassetid://4540931147" } uis.InputBegan:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseButton1 and not char:FindFirstChildOfClass("Tool") and not cooldown then cooldown = true startTime = tick() --------TIMER SCRIPT[[ spawn(function() if(tick() - startTime) > maxTime then startTime = tick() current = 1 print("waited too long, combo reseted to first animation") end end) ----------TIMER SCRIPT END]] local hum = char:FindFirstChild("Humanoid") local a1 = Instance.new("Animation") a1.AnimationId = animTable[current] local track = hum:LoadAnimation(a1) track:Play() track.KeyframeReached:Connect(function(frame) if frame == "Hit" then local part = Instance.new("Part") end end) track.Stopped:Connect(function() if current ~= #animTable then current = current + 1 else current = 1 end print(current) cooldown = false end) end end)
In your spawn() function, you don't have a loop to constantly check to see if it needs to reset their current combo. So it'll run a single time once you spawn the function, and of course since it's running only once as soon as you spawn the function, the passed time won't be passed your maxTime
With that being said, this should fix your problem
local uis = game:GetService("UserInputService") local runservice = game:GetService("RunService"); local repstorage = game:GetService('ReplicatedStorage') local events = repstorage:FindFirstChild("Events") local modules = repstorage:FindFirstChild("Modules") local player = game.Players.LocalPlayer local char = player.Character or player.CharacterAdded:Wait() repeat wait() until player:HasAppearanceLoaded() local current = 1 local cooldown = false local startTime = tick() local maxTime = 1.5 local animTable = { "rbxassetid://04540124455", "rbxassetid://04540153886", "rbxassetid://04540429673", "rbxassetid://4540628785" , "rbxassetid://4540931147" } uis.InputBegan:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseButton1 and not char:FindFirstChildOfClass("Tool") and not cooldown then cooldown = true startTime = tick() --------TIMER SCRIPT[[ spawn(function() repeat -- loop added so it's constantly checking runservice.Heartbeat:Wait() until (tick() - startTime) > maxTime startTime = tick() current = 1 print("waited too long, combo reseted to first animation") end) ----------TIMER SCRIPT END]] local hum = char:FindFirstChild("Humanoid") local a1 = Instance.new("Animation") a1.AnimationId = animTable[current] local track = hum:LoadAnimation(a1) track:Play() track.KeyframeReached:Connect(function(frame) if frame == "Hit" then local part = Instance.new("Part") end end) track.Stopped:Connect(function() if current ~= #animTable then current = current + 1 else current = 1 end print(current) cooldown = false end) end end)