function HitboxModule.new(hitboxPart, damage, owner) local self = setmetatable({}, {__index = HitboxModule})
-- when swinging hitbox:Activate() task.wait(0.3) -- swing duration hitbox:Deactivate() public class Hitbox : MonoBehaviour { public float damage = 10f; public GameObject owner; private bool isActive = false; private HashSet<GameObject> hitTargets = new HashSet<GameObject>(); public void Activate() { isActive = true; hitTargets.Clear(); }
Health targetHealth = other.GetComponentInParent<Health>(); if (targetHealth != null && other.gameObject != owner) { if (!hitTargets.Contains(targetHealth.gameObject)) { hitTargets.Add(targetHealth.gameObject); targetHealth.TakeDamage(damage); OnHit(targetHealth.gameObject); } } } hitbox script
function HitboxModule:Activate() self.Active = true self.HitCharacters = {} self.Connection = self.Part.Touched:Connect(function(hit) if not self.Active then return end
self.Part = hitboxPart self.Damage = damage or 10 self.Owner = owner self.Active = false self.HitCharacters = {} -- track already hit characters function HitboxModule
local hitbox = HitboxModule.new(swordPart, 25, owner)
function HitboxModule:Deactivate() self.Active = false if self.Connection then self.Connection:Disconnect() self.Connection = nil end end owner) local self = setmetatable({}
return self end
Follow us on Instagram ❤️