Combat System Taking Damage From Player Twice

I made a punch combat system using Region3. However, the player gets damage dealt twice.

Local Script:
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()

local UIS = game:GetService("UserInputService")
local Enabled = true
local RE = script:WaitForChild("Function")
UIS.InputBegan:Connect(function (input, GPE)
	
	if GPE then return end
	
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		if Enabled == true then
			RE:FireServer("Combat", char.HumanoidRootPart.CFrame * CFrame.new(0,0,-2.5).Position)
			Enabled = false
			wait(0.3)
			Enabled = true
		end
		
	end
end)

Server Script:

local RE = script.Parent
local Enabled = true
local combo = 1

RE.OnServerEvent:Connect(function(player, action, Pos)
	local char = player.Character or player.CharacterAdded:Wait()
	if Enabled == false then return end
	Enabled = false
	if action == "Combat" then
		if combo == 1 then
			combo = 2
			local Track = Instance.new("Animation")
			Track.AnimationId = "rbxassetid://7008354558"
			local Anim = char.Humanoid:LoadAnimation(Track)
			Anim:Play()
			local playingTracks = char.Humanoid.Animator:GetPlayingAnimationTracks()
			for i, v in pairs(playingTracks) do
				if v.Name == "walk" or v.Name == "run" then
					v:Destroy()
				end
			end
			
		elseif combo == 2 then
			combo = 1
			local Track = Instance.new("Animation")
			Track.AnimationId = "rbxassetid://7008358588"
			local Anim = char.Humanoid:LoadAnimation(Track)
			Anim:Play()
			local playingTracks = char.Humanoid.Animator:GetPlayingAnimationTracks()
			for i, v in pairs(playingTracks) do
				if v.Name == "walk" or v.Name == "run" then
					v:Destroy()
				end
			end
		end
		if char.Humanoid:FindFirstChild("Whoosh") then
			local whoosh = char.Humanoid:WaitForChild("Whoosh")
			whoosh:Play()
		else 
			local sound = Instance.new("Sound", char.Humanoid) 
			sound.Name = "Whoosh"
			sound.SoundId = "rbxassetid://231731980"
			sound.PlaybackSpeed = math.random(88, 120)/100
			sound:Play()
			
		end
			
		wait(0.2)	
		
		local region = Region3.new(Pos - Vector3.new(2.5, 2.5, 2.5), Pos + Vector3.new(2.5, 2.5, 2.5))
		local RTable = workspace:FindPartsInRegion3(region, nil, 20)
		
		for i, v in pairs(RTable) do
			if v.Parent:FindFirstChild("Humanoid") and v.Parent:FindFirstChild("Deb") == nil and v.Parent ~= char then
				local Deb = Instance.new("BoolValue", v.Parent)
				Deb.Name = "Deb"
				game.Debris:AddItem(Deb, 0.2)
				local randomDMG = math.random(20,25)
				v.Parent.Humanoid:TakeDamage(randomDMG)
				print(randomDMG)
				
				if v:FindFirstChild("Punch") then
					local punch = v:WaitForChild("Punch")
					punch:Play()
				else 
					local s = Instance.new("Sound", v)
					s.Name = "Punch"
					s.SoundId = "rbxassetid://3932505023"
					s.PlaybackSpeed = math.random(88, 120)/100
					s:Play()
				end
				local attachment1 = Instance.new("Attachment", v)
				local fx = game.ServerStorage:WaitForChild("FX")
				local punchFX = fx:WaitForChild("PUNCH")
				local random = math.random(0, 2)
				
				if random == 1 then
					
					local particle = punchFX.Effects2:Clone()
					particle.Parent = attachment1
					particle:Emit(10)
					wait(0.2)
					particle:Destroy()
					print("ELLLO")
					
				elseif random == 2 then
					
					local particle = punchFX.HitModuleParticle:Clone()
					particle.Parent = attachment1
					particle:Emit(10)
					wait(0.2)
					particle:Destroy()
					print("ELLO 2")
					
				end
				
				end
		end
		wait(0.3)
		Enabled = true
	end
	
end)

This is the layout in the explorer. Screen Shot 2021-06-27 at 8.35.44 PM

1 Like

I did though

if Enabled == false then return end
	Enabled = false

I think the problem is that the region3 detects the player twice or something.

1 Like

Maybe try changing the setup of the debounce to

if Enabled == true then 
	Enabled = false
    --the rest of your code
else
      return
end
1 Like

I would recommended not to use a local value in my opinion
I think that using a boolvalue (which is an instance) is better since you can check the value everytime you testing

Is the double damage dealth instantly or is there a time between each damage taken? If it’s instantly then just do randomDMG / 2 and save yourself some time trying to fix a bug and maybe return to this some time later, or try:

if v.Parent:FindFirstChild("Deb") then
return 
end

I think I’ll try dividing by 2. There isn’t really a time difference between each print. I don’t want to get burnt out.

Or it might be that you added the player in the RTable twice, do some debugging and print all the values inside the table

It fixed by itself somehow. Idk