function newHitbox(character, size, offset, damage, linger)
local hrp = character:FindFirstChild("HumanoidRootPart")
if hrp == nil then return end
local weld = Instance.new("WeldConstraint", hrp)
local hitbox = Instance.new("Part")
weld.Part0 = hrp
weld.Part1 = hitbox
hitbox.CanCollide = false
hitbox.CanQuery = false
hitbox.Massless = true
hitbox.Transparency = 0.5
hitbox.Material = Enum.Material.ForceField
hitbox.BrickColor = BrickColor.new("Really red")
hitbox.Size = size
hitbox.CFrame = hrp.CFrame + hrp.CFrame.LookVector * offset + Vector3.new(0, offset.Y)
hitbox.Parent = character
hitbox.Touched:Connect(function(hit)
local hum = hit.Parent:WaitForChild("Humanoid")
local isBlocking = hum:FindFirstChild("isBlocking")
local BlockDmg = damage / 25
hum.WalkSpeed = 0
task.wait(2)
hum.WalkSpeed = 16
if hit.Parent:FindFirstChild("Humanoid") == nil then return end
for _, v in pairs(hitbox:GetChildren()) do
if v:IsA("ObjectValue") then
if v.Value == hit.Parent then return end
end
end
local hitCounter = Instance.new("ObjectValue", hitbox)
hitCounter.Value = hit.Parent
local blockdamage = damage / 25
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
local isBlocking = Humanoid:FindFirstChild("isBlocking")
if isBlocking == false then
hit.Parent.Humanoid:TakeDamage(damage)
else
hit.Parent.Humanoid:TakeDamage(blockdamage)
end
end)
task.wait(linger)
hitbox:Destroy()
end
hitboxEvent.OnServerEvent:Connect(function(plr, size, offset, damage, linger)
newHitbox(plr.Character, size, offset, damage, linger)
end)