Im making a fighting game and i am using my own hit box system. It uses overlaps and then searches the returned parts for humanoids to damage. Ive tried making it detect if the humanoid is already inside the detected humanoids table, but it still ends up detecting the same humanoid.
Hitbox function:
function HitboxModule.Box(CF:CFrame, Size:Vector3, Blacklist:{Instance}?)
local Params = OverlapParams.new()
if Blacklist then
Params.FilterType = Enum.RaycastFilterType.Exclude
Params.FilterDescendantsInstances = Blacklist
end
local BoundsCheck = workspace:GetPartBoundsInBox(CF, Size, Params)
return BoundsCheck
end
Function to search for humanoids in a list of instances:
function HitboxModule.GetHumanoids(Instances:{Instance})
local Humanoids = {}
for i, instance in pairs(Instances) do
local Humanoid = instance.Parent:FindFirstChild("Humanoid")
if Humanoid then
if not table.find(Humanoids, Humanoid) then
Humanoids[i] = Humanoid
end
end
end
print(Humanoids)
return Humanoids
end
Before i added the table.find() check, it would damage the same Humanoid 6 times (Because of its 6 parts). Now, if theres two humanoids together, it will damage one once and the other 7 times. I have no idea why this is happening and i cant find anything similar that other people have talked about.
For extra info, i have a custom damage system being used.
Here:
local PartsHit = HitboxModule.Box(HitboxCFrame, Vector3.one*3)
--[[local Part = Instance.new("Part", workspace)
Part.CanCollide = false
Part.Anchored = true
Part.Transparency = .5
Part.CFrame = HitboxCFrame
Part.Size = Vector3.one*3--]]
local Humanoids = HitboxModule.GetHumanoids(PartsHit)
for i, Humanoid in pairs(Humanoids) do
local Char = Humanoid.Parent
local StatManager = require(Char.StatManager)
local AttackInfo = {}
AttackInfo.Damage = 10
AttackInfo.Knockback = (HumanoidRootPart.CFrame * CFrame.Angles(math.rad(45), 0, 0)).LookVector * 35
AttackInfo.Stun = .85
AttackInfo.Ragdoll = true
local Return = StatManager.TakeDamage(AttackInfo)
if Return == "Hit" or "Kill" then
local PunchSound = SFX.PunchSound:Clone()
PunchSound.Parent = Char.HumanoidRootPart
end
end
But i dont know if thats the issue or if its the humanoid searching function. I think its the function because ive used some print debugs and found that it put the same humanoid in the list 7 times. And i’ve also checked to make sure that it wasnt the StatModule thing i was using. And it shows that its being trigger 7 times on the same humanoid. Any help’s appreciated!