Hey guys, so I made a hitbox for my game like a week ago and I just wanted to see if I could like improve on it to make it more reliable and better, if you get what I mean. Any tips would help!
Here’s the main script of the hitbox, and I’m also using OverlapParams.
local Hitbox = {Remote = script:WaitForChild("HitboxRemote")}
Hitbox.Settings = {
Damage = 10;
Size = Vector3.new(5,5,5);
DebrisTime = .75;
Offset = CFrame.new(0,0,-2.5)
}
---[Securing any nils value set in]---
setmetatable(Hitbox.Settings, {
__index = function()
return {
Damage = 10;
Size = Vector3.new(5,5,5);
DebrisTime = .75;
Offset = CFrame.new(0,0,-2.5)
}
end,
})
function Hitbox:CreateHitbox(plr)
self.Remote:FireServer(nil,"AntiCheat")
local HRP = plr.Character:FindFirstChild("HumanoidRootPart")
local HumTable = {}
local Part, Weld = game.ReplicatedStorage.HitPart:Clone(), Instance.new("WeldConstraint")
Part.Size = self.Settings["Size"]
Part.CFrame = HRP.CFrame * self.Settings["Offset"]
Part.Parent = game.Workspace.Hitboxes
Weld.Part0 = Part
Weld.Part1 = HRP
Weld.Parent = Part
game.Debris:AddItem(Part, self.Settings["DebrisTime"])
local Hum, Destroy, RenderStepped = nil, false, nil
local Params = OverlapParams.new()
Params.FilterType = Enum.RaycastFilterType.Blacklist
Params.FilterDescendantsInstances = {plr.Character, Part}
Params.MaxParts = 50
RenderStepped = game:GetService("RunService").RenderStepped:Connect(function()
local HitTable = game.Workspace:GetPartsInPart(Part, Params)
for i,v in ipairs(HitTable) do
local Humanoid = v.Parent:FindFirstChildWhichIsA("Humanoid")
if Humanoid ~= nil then
if not table.find(HumTable, Humanoid) then
table.insert(HumTable, Humanoid)
self.Remote:FireServer(Humanoid.Parent)
end
end
end
end)
task.spawn(function()
Part.Destroying:Connect(function()
RenderStepped:Disconnect()
end)
end)
end
return Hitbox