How to Stop the m1 local script from keep doing m1s on stun

How to Stop the m1 local script from keep doing m1s on stun.
i have a fucntion that checks if the player is stunned i have tried many ways to stop the m1 but it didnt work like i wanted to.
– My Script

local player = game.Players.LocalPlayer  -- Player Varialbels
local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")

--Variabels
local combo = 1 
local Remote = RS.Remotes:WaitForChild("EventBlackLeg")
local Equiped = false
local debounce = false
local data = nil

-- Settings
local Cooldown = 0.5


-- Check if tools is equiped 
script.Parent.Parent.Equipped:Connect(function()
	Equiped = true
end)
script.Parent.Parent.Unequipped:Connect(function()
	Equiped = false
end)

-- UserInput
UIS.InputBegan:Connect(function(input)
	local character = player.Character

	character:GetAttributeChangedSignal("Stunned"):Connect(function()
		print("stunned")		
	end)
	if input.UserInputType == Enum.UserInputType.MouseButton1 and Equiped == true and debounce == false then
		

	
		
		if combo == 1 and debounce == false  then
			-- if the combo is 1 

			debounce = true

			data = "Punch1"
			Remote:FireServer(data)
			combo = 2
			print(combo..data)
			wait(Cooldown)
			debounce = false

		elseif combo == 2 and debounce == false then -- if combo is 2

			debounce = true

			data = "Punch2"
			Remote:FireServer(data)
			combo = 3
			print(combo..data)
			wait(Cooldown)
			debounce = false

		elseif combo == 3 and debounce == false then
			debounce = true

			data = "Punch3"
			Remote:FireServer(data)
			combo = 4
			print(combo..data)
			wait(Cooldown)
			debounce = false

		elseif combo == 4 and debounce == false then
			debounce = true

			data = "Punch4"
			Remote:FireServer(data)
			combo = 5
			print(combo..data)
			wait(Cooldown)
			debounce = false

		elseif combo == 5 and debounce == false then
			debounce = true

			data = "Punch5"
			Remote:FireServer(data)
			combo = 1
			print(combo..data)
			wait(Cooldown)
			debounce = false


		end		
	end



end)
	

A simple debounce could fix this problem.

First off, you can simplify your code a bit. If you notice in the if-else statement, you’re repeating parts of your code in each statement. This can be greatly simplified by only putting it once at the end once you have all the data you need.

Also, a much simpler method than accounting for each individual combo move would be to use the modulus operator (%) to get the remainder so you can loop through the different punch options.

local player = game.Players.LocalPlayer  -- Player Variables
local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")

--Variables
local Remote = RS.Remotes:WaitForChild("EventBlackLeg")
local data = "Punch%d"
local Equipped = false
local debounce = false
local combo = 1

-- Settings
local Cooldown = 0.5
local MaxCombos = 5


-- Check if tools is equiped 
script.Parent.Parent.Equipped:Connect(function()
	Equipped = true
end)
script.Parent.Parent.Unequipped:Connect(function()
	Equipped = false
end)

-- UserInput
UIS.InputBegan:Connect(function(input)
	local character = player.Character
	if debounce or (not Equipped) or (not character) or character:GetAttribute("Stunned") or (input.UserInputType ~= Enum.UserInputType.MouseButton1) then return end -- debounce
	
	debounce = true
	Remote:FireServer(data:format(combo))
	combo = (combo%MaxCombos)+1
	task.wait(Cooldown)
	debounce = false
end)
3 Likes

Yea i was consider doing something like this but i am not fully done with the system

I used this in the If statement and it worked. Script: and (not character:GetAttribute(“Stunned”))

A debounce would bug it. it stacks.