Punch System Bug

Hi, I’m creating a strength simulator game, and I’m having trouble with the melee system (punch tool). I am using a local script and a server script in my punch tool to detect when the player punches, if what the player punched is a player, to take damage, and if the punched player’s health is at 0 (died) to increase the player’s kill streak and reset the punch player’s kill streak. The problem I have with this system is it triggers too many times. Someone with damage 30 can kill someone with health 480. Because it triggers so many times, the kill streak increases by 13-16. I am unsure of how to fix these issues.

Here is the local script


local PunchEvent = game.ReplicatedStorage.Punch
local Player = game.Players.LocalPlayer
local mouse = Player:GetMouse()

local debounce = false
script.Parent.Activated:Connect(function()
	if debounce == false then
		debounce = true
		wait(0.4)
		PunchEvent:FireServer(Player.Damage.Value)
		wait(1)
		debounce = false
	end
end)

Here is the server script (that is within the tool)

local tool = script.Parent
local PunchEvent = game.ReplicatedStorage.Punch
local combo = 0
local punchsfx = game.SoundService.PunchSFX

local debounce = false

PunchEvent.OnServerEvent:Connect(function(Player, Damage)
	local player = game.Players:FindFirstChild(script.Parent.Parent.Name)
	if  debounce == false then
	combo = combo + 1
	if combo == 1 then
		local PunchAnim1 = Player.Character.Humanoid.Animator:LoadAnimation(script.Punch1)
		PunchAnim1:Play()
	end
	
	if combo == 2 then
		local PunchAnim2 = Player.Character.Humanoid.Animator:LoadAnimation(script.Punch2)
		PunchAnim2:Play()
	end
	
	if combo == 3 then
		local PunchAnim3 = Player.Character.Humanoid.Animator:LoadAnimation(script.Punch3)
		PunchAnim3:Play()
	end
	
	if combo == 4 then
		local PunchAnim4 = Player.Character.Humanoid.Animator:LoadAnimation(script.Punch4)
		PunchAnim4:Play()
		combo = 0
	end
	
	
	local HitBox = Instance.new("Part")
	local weld = Instance.new("Weld", HitBox)
	weld.Part0 = HitBox
	weld.Part1 = Player.Character.HumanoidRootPart
	weld.C1 = CFrame.new(0,0,-2.5)
	HitBox.Size =  Vector3.new(4, 4, 2)
	HitBox.BrickColor = BrickColor.new("Really red")
	HitBox.Transparency = 1
	HitBox.Position = Player.Character.HumanoidRootPart.Position
	HitBox.Massless = true
	HitBox.CanCollide = false
	HitBox.Parent = Player.Character
	
	
	HitBox.Touched:Connect(function(Part)
			if Part.Parent:FindFirstChild("Humanoid")  and  debounce == false then
				local PunchedPlayer = game.Players:FindFirstChild(Part.Parent.Name)
				if Player.CanHeal.Value == true and Player.CanDamage.Value == true then
					wait(1)
					PunchedPlayer.Character.Humanoid.Health = PunchedPlayer.Character.Humanoid.Health - Damage
					print(Damage)
					PunchedPlayer.CurrentHealth.Value = PunchedPlayer.Character.Humanoid.Health
					if PunchedPlayer.Character.Humanoid.Health <= 0 then
						PunchedPlayer.leaderstats.KillStreak.Value -= PunchedPlayer.leaderstats.KillStreak.Value
						Player.leaderstats.KillStreak.Value = Player.leaderstats.KillStreak.Value + 1
					end
				punchsfx:Play()
				HitBox.CanTouch = false
				wait(1)
				HitBox.CanTouch = true
					debounce = true
			end
		end
	end)
	wait(1)                                                                                                                       
	debounce = false
	HitBox:Destroy()
	end
end)

Any suggestions would help, thanks so much!!

Create a cooldown variable, make a loop that decrements it if it’s activated, and run a check before a player receives damage that the cooldown is complete.

1 Like