So i have this hitbox that appears where the player that used the move is, and i wanted everyone nearby to take damage. so i made this script and for some reason it only prints once so im guessing it only detected one humanoid when there were multiple nearby
local HitBox = game.ReplicatedStorage.Taijutsu.KickHitbox:Clone()
HitBox.Parent = workspace
HitBox.Position = HumanoidRootPart.Position
HitBox.Touched:Connect(function(hit)
local ehum = hit.Parent:findFirstChild("Humanoid") or hit.Parent.Parent:findFirstChild("Humanoid")
if ehum and ehum ~= player.Character.Humanoid then
print("hit")
HitBox:Destroy()
end
end)
well, you’re destroying it after one person touches it which disconnects the .Touched signal. You could have it last for x amount of time, and each time someone touches it while it is active add them to a table, and then after the time is over damage them all or whatever else.
you could do something like this. This isn’t the entirety of it but an example
function startHitDetection(player, hitbox, duration)
local Hit_Humanoids = {}
local connection = hitbox.Touched:Connect(function(hit)
local ehum = hit.Parent:findFirstChild("Humanoid") or hit.Parent.Parent:findFirstChild("Humanoid")
if ehum and ehum ~= player.Character.Humanoid and not table.find(Hit_Humanoids, ehum) then
table.insert(Hit_Humanoids, ehum)
print("Added Humanoid")
end
end)
task.delay(duration, function()
if connection then
connection:Disconnect()
return Hit_Humanoids
end
end)
end
-- to use it do something like:
local HitBox = game.ReplicatedStorage.Taijutsu.KickHitbox:Clone()
HitBox.Parent = workspace
HitBox.Position = HumanoidRootPart.Position
local humanoids = startHitDetection(Player, HitBox, 5) -- do it for 5 seconds
-- humanoids is a table full of everyone that it hit
for i,humanoid in pairs(humanoids) do
humanoid:TakeDamage(20) -- do whatever here
end