What do you want to achieve? Keep it simple and clear!
I’m trying to make a fist tool that allows for the player to continue a combo if it is clicked again within a certain amount of time.
What is the issue? Include screenshots / videos if possible!
I’m finding it hard to achieve what I’m looking for. I know it has something to do with “tick()” but my brain hurts just thinking about how that would work. If I click the tool once, establishing the first click time, and then click again, it won’t update a separate 'currentClick" variable, but just overwrite the first click.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried looking up “combo” or “combat” on the Dev Hub to no avail. I’ve also tried several times to script my own combo system, but that doesn’t work either. Below is one of my attempts.
local click = true --Establishing a Clicked variable
lastTimeM1 = tick()
combo = combo + 1
print(combo)
click = false
if click == true then --Attempting to detect a second click
currentM1 = tick()
if currentM1 - lastTimeM1 <= 1.5 then --If time is less than 1.5 seconds
combo = combo + 1
if combo == 4 then
print("Combo Finished!")
combo = 0
end
elseif currentM1 - lastTimeM1 > 1.5 then --If time is greater than 1.5 seconds
print("Combo Reset!")
return
end
end
end)
I know this isn’t exactly the best script, and I already know that it doesn’t work as intended, but I’m really unsure where to go from here. I’ve looked up YouTube videos, I’ve looked on the forums, and found nothing. I’d like it if someone could explain to me how I would detect the brief period in between clicks to determine if the combo should continue or not.
I mean you are on the right track, you should be using tick(). I think you just need to update the “CurrentM1” everytime you click [to restart the combo cooldown thing], but after you check the tick() has been under 1.5.
i adapted some stuff, if something goes wrong, tell me
local UIS = game:GetService("UserInputService")
local D = false -- debounce
local streak = 0 -- combo streak
local ActualTime = nil
local OldTime = nil
local PassedTime = nil
local Attacking1 = false
local Attacking2 = false
UIS.InputBegan:Connect(function(input, gameProcessed)
if streak >= 0 and input.UserInputType == Enum.UserInputType.MouseButton1 then
if D == false then
D = true
ActualTime = time()
PassedTime = ActualTime - OldTime
if PassedTime < 1 then -- IF pASSED time is lesser than 1 then
streak = streak + 1
print"+1 Streak"
else
streak = 1 -- since it's 0, it will add anyway, this was to prevent some bug where the streak would not count
OldTime = time() -- This resets the timer cooldown
end
else if D == true then -- debounce makes sure you will not spam attacks
print"Already Attacking, wait a while..."
return
end
end
end
if streak == 1 and D == true then -- Ataque 1
if Attacking1 == true then
print"Attack 1 is on the Queue, wait a while"
return
end
if Attacking1 == false then
ActualTime = time()
OldTime = time()
PassedTime = ActualTime - OldTime
Attacking1 = true
--Play some animation here
print"First Attack"
--print(PassedTime)
--Animation.Stopped:Wait() -- wait until the animation stops, otherwise it may be really weird
D = false
Attacking1 = false
return
end
else if streak == 2 and D == true then
if Attacking2 == true then
print"Attack 2 is on the Queue, wait a while"
return
end
if Attacking2 == false then
ActualTime = time()
OldTime = time()
PassedTime = ActualTime - OldTime
Attacking2 = true
--Play Animation
print"Second Attack"
--print(PassedTime)
--Animation.Stopped:Wait()
D = false
Attacking2 = false
return
end
end
end
end)
looks kinda weird, it was because i dind’t studied everything, i just tried to find the cooldown and i was just messing up with tick and time and replacing stuff
Ended up using Time(), since i saw posts in devforum where they said Tick() was getting deprecated, that’s why i was using Time()
Tried it out, got the error: “attempt to perform arithmetic (sub) on number and nil” referring to line 23. I think it’s because OldTime wasn’t set yet.