How to code a variably speeding up bomb countdown using a single beeping sound

I’m looking for a system that can make a bomb ticking sound that gets faster the closer the timer reaches to zero. This usually wouldn’t be a problem but the timer is variable and randomized. I can’t seem to get something down that works variably the closer the timer gets to one. anyone able to help me out on this?
Code portion is below

local countnumber = (math.random(4,6))

local function bombtick()
	local sound = script.Parent["Siren Blat 1 (SFX)"]
	while countnumber > 0 do
		wait(1)
		countnumber -= 1
		
	end
end

You can achieve this by making the wait time a function of the remaining time.

local countnumber = math.random(4, 6)

local function bombtick()
    local sound = script.Parent["Siren Blat 1 (SFX)"]
    while countnumber > 0 do
        sound:Play()
        
        -- Calculate wait time based on the remaining countnumber
        local waitTime = countnumber / 10
        
        wait(waitTime)
        countnumber -= 1
    end
   
end

bombtick()
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.