Have a delay between resetting the m1 combo when it reaches 5

function setCombo(char)
	local combo = char:GetAttribute("Combo")
	
	if combo < MaxCombo then
		char:SetAttribute("Combo", combo+1)
		
	else
		char:SetAttribute("Combo", 1)
	end
	
end

function resetCombo(char, oldcombo)
	task.delay(1.2, function()
		local currentcombo = char:GetAttribute("Combo")

		if oldcombo == 5 then return end

		if currentcombo-1 == oldcombo then
			char:SetAttribute("Combo",1)
		end		
	end)
end

I have here 2 functions, they set the attribute combo to 1 when you don’t click anything for 1 second, or when you’re at MaxCombo (5),

if info.Key == Enum.UserInputType.MouseButton1 then
		if sf.SetCooldown({plr = player, ability = "Punch", check = true}) then return end
		
		local combo = char:GetAttribute("Combo")

		if combo > MaxCombo then return end
		
		sf.SetCooldown({ plr = player, ability = "Punch", dura = .5})
		
		print(combo)
		
		setCombo(char)
		resetCombo(char, combo)
	end

In here, each time you click with your mouse it calls those 2 functions, what I want to achieve is making it so that when u reach MaxCombo (5), it delays the resetting of the combo back to 1, by 1 second and in thee span of that one second you’re a bit slowed, and you can’t click or cast any abilities… How would I do that?

1 Like

From what I gather from these scripts, you would have to use your cooldown function/module to cooldown the player 1 second, then lower their walk speed. I don’t really understand the issue because you should be able to just task.wait(delay) when you set it to 1. I’m sorry if this wasn’t a valid solution, I just don’t really understand what you are looking for or how the script works. If you don’t want the task.wait to yield the entire thread, you can use task.spawn to separate the combo logic into its own thread.

2 Likes

Fixed it, by using collection service…

if info.Key == Enum.UserInputType.MouseButton1 then
		if sf.SetCooldown({plr = player, ability = "Punch", check = true}) then return end
		
		if collectionService:HasTag(char, "M1Pause") then return end
		
		sf.SetCooldown({plr = player, ability = "Punch", dura = .5})
		
		local Combo = char:FindFirstChild("Combo")
		local lastTimeClicked = char:FindFirstChild("lastTimeClicked")
		
		local Animation = repStorage.Anims.PunchAnim:GetChildren()
		
		if tick()-lastTimeClicked.Value > 2.5 then
			Combo.Value = 0
		end
		
		lastTimeClicked.Value = tick()

		if Combo.Value >= MaxCombo then
			
			collectionService:AddTag(char, "M1Pause")
			Combo.Value = 0
			task.delay(1, function()
				collectionService:RemoveTag(char, "M1Pause")
			end)
			return
		end		
		
		repStorage.Remotes.AttackEvent:FireClient(player, "LoadAnim", {Animation = Animation[Combo.Value], human = human})
		
		Combo.Value += 1
		print(Combo.Value)
		
	end

I have one question though, the ‘Local Animation = repStorage.Anims.PunchAnims:GetChildren()’
I’m using a number value for combo’s, I’m trying to get the anims 1,2,3,4,5 based on what combo I have… as u can see my way of trying to do that, it didn’t work… Can you help?

Make sure you turn the search for Combo.Value into a string, since the name is always a string, it will never find anything with a number in its name. That’s the only error I see with it.

You can do this by simply typing tostring(Combo.Value) in the brackets instead.

I fixed it, never mind. I called the loadanimation before setting the combo value to 1, so it would be Punch0 instead of Punch1

1 Like

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