Timer pass down to a new created function and reset all

i have some issues with this script, because this is like a trigger for making a key combination, so variable “timee” is a timer for if you didnt do any key combination after the timer then variables goes false and all that stuff, but if i do a combination right there, and then i trigger again this function the timer that i had before goes and then turn all false, i dont understand how to solve this

local module = {}
local abilityss, spec = require(game.ServerScriptService.Main["data stuff"].Standlist), require(game.ServerScriptService.Main["data stuff"].SpecStuff.SpecList)

function module.Start(player: any, typee: boolean)
	local gui = player.PlayerGui.PlayerBar.Ultimate_Screen
	local ui = player.PlayerGui.PlayerBar.Player_Ui
	local timee = 10
	
	local currentrage1 = player:WaitForChild("PvpFolder"):WaitForChild("RageFolder").RageAbility.Rage
	local currentrage2 = player:WaitForChild("PvpFolder"):WaitForChild("RageFolder").RageSpec.Rage
	ui.Visible = false
	gui.Visible = true
	player.Character:SetAttribute("Doing_Combination", true)
	player.Data:WaitForChild("GuiBeingUse").Value = true
	if typee == true then
		player.Character:SetAttribute("Type_Combination", "ability")
	else
		player.Character:SetAttribute("Type_Combination", "style")
	end
	task.wait(timee)
	if typee == true then
		currentrage1.Value = 0
	else
		currentrage2.Value = 0
	end
	gui.Visible = false
	ui.Visible = true
	player.Data:WaitForChild("GuiBeingUse").Value = false
	player.Character:SetAttribute("Doing_Combination", false)
	player.Character:SetAttribute("Type_Combination", "none")
end

return module

this is the part that reset everything:

	task.wait(timee)
	if typee == true then
		currentrage1.Value = 0
	else
		currentrage2.Value = 0
	end
	gui.Visible = false
	ui.Visible = true
	player.Data:WaitForChild("GuiBeingUse").Value = false
	player.Character:SetAttribute("Doing_Combination", false)
	player.Character:SetAttribute("Type_Combination", "none")

(this is on server)

Are you looking to cancel the old timer? An easy way to ignore the old timer is to have an ID for the current timer stored as a variable, and then only to do the reset code if the current ID is the same as the one stored for the timer:

local currentTimerID = 0
local function startTimer()
    -- Increase the timer ID so old timers know they shouldn't do anything
    currentTimerID += 1
    -- Store the ID of this timer
    local myTimerId = currentTimerID
    -- Do your setup
    task.wait(10)
    -- Detects if a new timer was made during the task.wait, and if there was, it ignores the current timer
    if myTimerId ~= currentTimerID then
        return
    end
    -- Do your stuff after the timer
end

can you reset after the

    if myTimerId ~= currentTimerID then
        return
    end

?

That if statement runs when an older time finishes but there is a newer timer.

You could start a new timer in that if statement, but that would override the other timer overriding the timer with that if statement and wouldn’t lead to useful behavior (it would cause a chain reaction, since overridden old timers would create new timers that override any current timers and so on).


It might be helpful if you could explain the exact behavior you’re looking for, I’m not sure what you want the code to do.

so, im making a mechanic, that is basicly a key combination, something like mortal kombat fatality but without the “fatality” factor.
is more like a special attack, you have a 3 seconds of time to make a combination of key
something like “W-W-W-E”, if you didnt do any combination you just lost your ult bar (like tsb ultimate bar) is like a mix of tsb and fatality mechanic.
the function that i send is the trigger that allow you to:

  • open a ui

  • allow you to type the combination throw send arguments and bla bla

  • enabled some attribute to check

  • and the time for making the combination

and not forgot to mention that you accomplish a key combination immediately you do the special attack.