[Help me] Detect how many seconds have passed before a value has changed

Hello developers :smile:, today I was making a combat system. Basically, every time you click a value is added and they are called combos. At the moment the player is in combo 4 and is holding space an animation should play, at this moment I want a script to detect how many seconds he was in combo 4, this will help me to make a special attack. I am trying to use tick(), but I can’t do it. I would appreciate your help. I use translator by the way.

Script: (Not full script)

			if UIS:IsKeyDown("Space") and combo == 4  and CanAir then -- If you are holding Space and it is in Combo 4
				CanAir = false
				AirStatus = "Up"
				animation.AnimationId = airAnims[1]
			elseif not UIS:IsKeyDown("Space") and combo == 5 and not CanAir  then -- If you are NOT holding Space and are in Combo 5			
				if tick() - timepass < .5 then --- no work
						animation.AnimationId = airAnims[2]
					    AirStatus = "Down"

				animation.AnimationId = punchAnims[combo]	

You can try to make while loop with wait () to count the time

The code you have should be working. Where do you set timepass = tick()?


Make it in another script and connect them with int value or boolean value but you can make this while loop in the function

I’m not quite sure if it will work, isn’t there a way to do it in the script?

Coroutines should be able to run a loop inside of the script without delaying/stopping the rest of the script.