local module = require(game.ServerStorage.MuchachoHitbox)
local hitbox = module.CreateHitbox()
hitbox.Size = Vector3.new(10, 10, 10)
hitbox.CFrame = CFrame.new(0, 5, 15)
local hitplrs = {}
hitbox:Start()
hitbox.Touched:Connect(function(hit)
print(hit)
if hit.Name == "HurtBox" then
if table.find(hitplrs, hit.Parent.Name) then return end
table.insert(hitplrs, hit.Parent.Name);
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 10
end
end)
I put a hurtbox inside the player but if any part of the player is hit before the hurtbox then it breaks and stops doing anything.
The reason for this is the condition on line 14. After the first instance in which a player has been registered in hitplrs, the code will never reach line 16 for that player.
that’s not the problem, the player only get’s registered to hitplrs if the hitbox hit’s their hurtbox but it still stops working when the player’s character touches the hitbox before their hurtbox. it just doesn’t detect anything after the first hit.
it does, i’ve used code like this before and it always worked, i mean this is the first time i’ve used this system so i might go back to something else
In Default mode, it gets blocked by the Humanoid internally. or at least that’s what I think. So the Touched event doesn’t fire the way you’d expect.
There’s a HitParts mode, which would be more suitable in your case.
hitbox.DetectionMode = "HitParts"
local hitplrs = {}
hitbox:Start()
hitbox.Touched:Connect(function(hit)
if hit.Name == "HurtBox" then
local character = hit.Parent
if character and character:FindFirstChild("Humanoid") then
if table.find(hitplrs, character.Name) then return end
table.insert(hitplrs, character.Name)
character.Humanoid.Health = character.Humanoid.Health - 10
print(hit.Name)
end
end
end)