Combat timer with ticks issue

I wanted to make simple timer system for my combat to reset combo.

My issue is with ticks that are not counting from 0 but with the last click. And that will cause situations where if player will wait for example 1 minute or two, without clicking he needs to click more times to count one combo. (Sorry for miss spells, or even bad english)

--Services
local UIS = game:GetService("UserInputService")
local runService = game:GetService("RunService")
local repStorage = game:GetService("ReplicatedStorage")

--Combo related
local punchEvent = repStorage.PunchSignal
local prevTick = tick()
local combo = 0

--Main function
local function PunchInput(input: InputObject, processed)
	if processed then return end
	
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		local accTick = tick() - prevTick
		if accTick < .7 then
			if combo > 2 then
				
				combo = 0
			else
				
				combo += 1
			end
		else
			
			combo = 0
		end
		print("tick: "..accTick)
		
		punchEvent:FireServer(combo)
		prevTick = tick()
	end
end

UIS.InputBegan:Connect(PunchInput)
1 Like

It look like that language barrier are indeed making this harder but if I understand correctly (from my assumption)

the combo 0 don’t exist and player won’t do combo if it’s 0

so instead of outright reset combo to 0 if player don’t click again within 0.7 seconds set it to 1 instead

so it would be like this

if input.UserInputType == Enum.UserInputType.MouseButton1 then
		local accTick = tick() - prevTick
		if accTick < .7 then
			if combo > 2 then
				
				combo = 0
			else
				
				combo += 1
			end
		else
			
			combo = 1
		end
		print("tick: "..accTick)
		
		punchEvent:FireServer(combo)
		prevTick = tick()
	end

You can correct me if I misunderstood your problem

1 Like

script works that if .7 is higher than acctick but how this variable would be higher if i wait 10 seconds and ticks will be equal to that time and i need to click few times(to make this variable below that .7) to make +1 to combo variable. I want to start it from 0 everytime instead of showing me time from prevous click or smth and clicking few times to make it below .7. You can even see it on my video that my tick is 4 seconds(because i was waiting that time) and i need to click 3 times to make this variable lower and +1 to combo

1 Like

I think you might misunderstood your code?

your code use prevsTick from last click which mean it work as intended the reason why you need to click a few time in video before it turn to +1 combo is because the delay between each click is more than 0.7 seconds which is how exactly you tell your code to do

if your tick start at 0 everytime then it will never reset to 0 except if player have combo more than 2 aka this condition will never met

1 Like

So how can i check time after making one click and after making last combo start from 0 and dont count time before click

Sorry. I just misunderstood my code and its working propertly. thanks for help

2 Likes

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