Double Sword Damage to both player and opponent

i’m suffering a big problem. i created a sword with many scripts. my problem is, when the player presses the plunge trigger and the player is touching the opponent’s sword, both the player and the opponent get damaged. why is this? use roblox lua code. Script 1 (LocalScript), Keybind Detector located at StarterPack (player.Backpack) → Default → Keybind Detector (Disabled):

local userInputService = game:GetService("UserInputService")
local player = script.Parent.Parent.Parent

local debounce = false  -- Add a debounce flag to prevent multiple firings

userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if not debounce and input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.M then
			debounce = true  -- Set debounce flag to true to prevent further firings
			game.ReplicatedStorage:WaitForChild("PlungeDown"):FireServer(player)
			wait(3)
			debounce = false  -- Reset debounce flag after the wait period
		end
	end
end)

Script 2: PlungeDownAnim (Regular Script) Location: StarterPack (player.Backpack) → Default → PlungeDownAnim:

local rep = game:GetService("ReplicatedStorage")

local plungedown = rep:WaitForChild("PlungeDown")

local Animation = script.Parent.Plunge_Down

plungedown.OnServerEvent:Connect(function(player)

local Character = player.Character

local Humanoid = Character.Humanoid

local player = game.Players:GetPlayerFromCharacter(Character)

print(Character.Name)

local AnimationTrack = Humanoid:LoadAnimation(Animation)

AnimationTrack:Play()

script.Parent.PlungeDownAnim.Disabled = true

script.Parent.PlungeDownManager.Disabled = false

script.Parent.DeepSFX:Play()

wait(1)

script.Parent.PlungeDownAnim.Disabled = false

script.Parent.PlungeDownManager.Disabled = true

end)

Script 3: PlungeDownManager (Regular Script) Location: StarterPack (player.Backpack) → Default → PlungeDownManager:

local DebounceTable = {}
local player = script:FindFirstAncestorWhichIsA"Player" or game:GetService"Players":GetPlayerFromCharacter(script.Parent.Parent)

script.Parent:WaitForChild("Hitbox").Touched:Connect(function(hit)
	if hit.Parent then
		if hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("Kill_Drone") == nil and hit.Parent.Name ~= player.Name then
			if DebounceTable[hit.Parent] == true then return end
			DebounceTable[hit.Parent] = true
			--Write Code Here
			if not hit.Parent:FindFirstChild("HealthName") then
				local Health = game.ReplicatedStorage.HealthName:Clone()
				Health.Parent = hit.Parent
			end
			if not hit.Parent:FindFirstChild("DeathManager") then
				local DeathManager = game.ReplicatedStorage.DeathManager:Clone()
				DeathManager.Parent = hit.Parent
				DeathManager.Enabled = true
			end
			if not hit.Parent:FindFirstChild("DroneFollower") then
				local DroneFollower = game.ReplicatedStorage.DroneFollower:Clone()
				DroneFollower.Parent = hit.Parent
				DroneFollower.Enabled = true
			end
			local damageafter = hit.Parent.HealthName.Value - 40
			if damageafter <= 0 then
				hit.Parent.HealthName.Value = 0
			else
				hit.Parent.HealthName.Value = damageafter
			end
			player.leaderstats.Slashes.Value += 1
			wait(1)
			DebounceTable[hit.Parent] = false
		end
	end
end)

Script 4: KeybindEquipped (Regular Script) Same location as every other script listed

local tool = script.Parent

tool.Equipped:Connect(function()

tool.KeybindDetector.Enabled = true

end)

tool.Unequipped:Connect(function()

tool.KeybindDetector.Enabled = false

end)

Can you please help me? Thanks. Note that there are zombies and players. The problem only applies to players.
Note: When there are 2 players, the code prints out the owner of the sword twice. When there is 1 player, the code prints out the owner of the sword once.

[EDITED] just to make it better to read and added one new script.

1 Like