Why does my hitbox system pick up the same entity multiple times when i have set it not to

i made a new general hitbox system and it works completely fine other than it picking up the same entity in the same hitbox and that then multiplies the damage.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local CollectionService = game:GetService("CollectionService")
local Debris = game:GetService("Debris")

local module = {}

local function ConvertToVector(CF)
	return typeof(CF) == "CFrame" and CF.Position or CF
end

module.Object = {
	["CreateInstance"] = function(RequestedInstance, Properties)
		local function CheckProperty(Object, Property)
			local Property = Object[Property]
		end

		local Object = Instance.new(RequestedInstance)

		for i, v in pairs(Properties) do
			if pcall(function()CheckProperty(Object, i)end) then 
				Object[i] = v
			end
		end

		return Object
	end,
	["GetPartsInBox"] = function(Part)
		local Connection = Part.Touched:Connect(function() end)
		local Results = Part:GetTouchingParts() 

		--Part:Destroy()
		Connection:Disconnect();
		Connection = nil;

		return Results;
	end,
}

module.Hitbox = {
	["GetPartsInBoundBox"] = function(Player,HitboxData)
		local Player = Player or game.Players.LocalPlayer
		local Character = Player.Character
		
		local Humanoid,Root = Character:FindFirstChild("Humanoid"), Character:FindFirstChild("HumanoidRootPart")
		
		local Hitbox = game.ReplicatedStorage.Assets.General.Hitbox
		Hitbox = Hitbox:Clone()
		
		local Transparency
		if Player.Settings.HitboxDisplay.Value == true then
			Transparency = 0.6
		else
			Transparency = 1
		end
		Hitbox.Size = HitboxData.Size
		Hitbox.Transparency = Transparency
		Hitbox.Orientation = Hitbox.Orientation or HitboxData.Orientation
		Hitbox.Parent = workspace.Effects
		Hitbox.Color = Color3.new(1, 0, 0)
		Hitbox.Material = Enum.Material.ForceField
		Hitbox.CanCollide = false
		Hitbox.CastShadow = false
		
		local weld = module.Object.CreateInstance(
		 "Weld",{Part0 = HitboxData.RelativePart or Character.HumanoidRootPart,
		   Part1 = Hitbox,
		   C0 = HitboxData.Offset or CFrame.new(0,0,-4)})
		weld.Parent = HitboxData.RelativePart or Character.HumanoidRootPart
		Debris:AddItem(Hitbox,HitboxData.WaitTime or 0.45)
		Debris:AddItem(weld,HitboxData.WaitTime or 0.45)
		
		local Zone = module.Object.GetPartsInBox(Hitbox)
		local IsHit, EntitieList = false, {}

		for _,Hit in ipairs(Zone) do
			if not Hit:IsDescendantOf(Character) and Hit.Parent and Hit.Parent:FindFirstChild("Humanoid") and IsHit == false then
				local Victim = Hit.Parent
				local EnemyHumanoid,EnemyRoot = Victim:FindFirstChild("Humanoid"), Victim:FindFirstChild("HumanoidRootPart")
				EnemyRoot.CFrame = CFrame.lookAt(EnemyRoot.Position,Root.Position)
				if Victim ~= Character and EnemyHumanoid.Health > 0 and not table.find(EntitieList,Victim) then
					if CollectionService:HasTag(Victim,"Hitable") then
						table.insert(EntitieList,Victim)
						print(Victim.Name)
						IsHit = true
						break
					end
				end
			end
		end
		return IsHit,EntitieList
	end,
}
return module

Can you show the script calling for the hitbox?

local HitResult,ValidEntities = Connections.Hitbox.Hitbox.GetPartsInBoundBox(Player,{
					Size = MoveStats.Hitbox.Size,
					Offset = MoveStats.Hitbox.Offset,
					RelativePart = Character[MoveStats.Hitbox.RelativePart]
				})

				if HitResult then
					for Index = 1, #ValidEntities do
						local Victim = ValidEntities[Index]
						
						local OneTarget = {}
						OneTarget[Victim] = getValues(Victim)
						
						Connections.DamageService.Object.AttackEngine(MoveStats,Victim)
					end
				end

So does it print(Victim.Name) multiple times? If so can you add a print down before the return and see it they alternate?

also it does print victim.name multiple times

Add print right above
return IsHit,EntitieList

i cant print victim because its not defined then

when i print a random thing it does it whenever even when it not in anything

Have you added any prints to the second script shown? Is it constantly getting called? If so what calls the second script?

i just checked the rest of the script isn’t multiplying it is only the hitbox and it is sending the victim multiple times to be damaged

Can you add a print(HitResult) above the if HitResult statement? I think whatever is calling it is calling it for every part so when it does hit it hits multiple times.

image

image
once u do it enough it starts multiplying

I found out what is multiplying the hitbox function. it is the getanimationreachedsignal function but I am not sure why

yeah might be the getanimationreachedsignal

use a connection and disconnect it before it doubles (in a loop)

can I have an example of how I should do this?

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