Hey developers, I’ve had made a Hitbox from scratch to myself thinking that It’d be nice to share it with all of you guys who needs it as well. I’ve made it easily “Customizable” and with an built in “Anti - Cheat” already and easy to read. Below it’s just me explaining on how to set it up/how it works.
Now I’m going to show you how the settings works, currently these are the only settings that I have right now.
Hitbox.Settings = {
Damage = 10;
Size = Vector3.new(5,5,5);
DebrisTime = .75;
Offset = CFrame.new(0,0,-2.5);
DebounceTime = 1;
}
-
So now I’ll explain on what all of them does. So firstly we have “Damage” as you know, it’s just to adjust how much damage you want to do on the players.
-
Then we have “Size”, this is for adjusting the size for the hitbox meaning if you set it for 10, it’ll have a bigger hitbox radius.
-
Now we got “DebrisTime”, This is for how long you want the hitbox to appear, after the time is up, the Hitbox would delete itself.
-
Then we have the “Offset”, this is used to help with the offset of the hitbox, meaning if you need the hitbox to the right, you’d make the offset to the right and so on.
-
Lastly, we have “DebounceTime”, this is for how long you want to wait after you spawned in a hitbox, meaning if you had it for “5” seconds, you’ll need to wait 5 seconds so that you can be able to spawn another hitbox.
Now, I’ll show you on how to use it. Firstly you need to download the [Module] that I’ll link down below, and then you’ll have to place the stuff in the correct locations, which is shown right now.
**Place “HitBoxSettings” and “HitPart” inside of “ReplicatedStorage”.
Place “HitboxDamage” inside of “ServerScriptService”.
Now, place “CD” and “UserInput” Inside of “StarterChracterScripts”, lastly place “Hitboxes” in the workspace to keep things clean.
Now, that you got everything set up right, we’ll show you how to use it inside the script. First off, you need to require the module first and then use the function from it, just like this.
local HitboxSettings = require(game.ReplicatedStorage:WaitForChild("HitBoxSettings"))
HitboxSettings:CreateHitbox(plr)
You need to send a “Player” bool to the parameter otherwise it won’t work, then to use the “DebounceTime”, it’s the same thing but just need to change it up a bit so like so. It goes the same with “Damage”.
task.wait(HitboxSettings.Settings["DebounceTime"])
:FindFirstChildOfClass("Humanoid"):TakeDamage(HitboxSettings.Settings["Damage"])
So now I’m just going to explain how this Hitbox works, so for the detection I’m using is “OverlapParams” which is great to use for Hitboxes like this, I’ve have tried my best to make it not lag when detecting BaseParts, so it shouldn’t make your performance feel worse when using it.
Below here is where you can add in a Blacklist/MaxParts, to improve the hitbox detection, The information for what they do is already listed inside the script.
local Params = OverlapParams.new()
Params.FilterType = Enum.RaycastFilterType.Blacklist
Params.FilterDescendantsInstances = {plr.Character, Part} -- Insert stuff here if you want to blacklist them for being detected.
Params.MaxParts = 50 -- How many items to be detected before it stops detecting.
Here’s the main detection, I’ve made it only detect the “BaseParts” for “performance”, as well used a table method to help blacklist the Humanoid that’s already has been damaged. Then at the end, when the Hitbox gets destroyed, the RenderStepped will be disconnected to prevent Memory leaks.
--[Main Humanoid Detection]--
RenderStepped = game:GetService("RunService").RenderStepped:Connect(function()
local HitTable = game.Workspace:GetPartsInPart(Part, Params)
for i,v in ipairs(HitTable) do
if v:IsA("BasePart") then
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
else
return
end
end
end)
--[Close the RenderStepped for Memory]--
task.spawn(function()
Part.Destroying:Connect(function()
RenderStepped:Disconnect()
end)
end)
Then here we have the “Anti - Cheat” that I have made to prevent “Spamming Hitboxes” and such. Below it’ll show how it works, It’ll first make a “BoolValue” on the server and it’ll parent into the Character’s “CD”, Then it’ll check if there’s any existing BoolValue or if there’s none, which leads into a Kick, since it only accepts with 1 BoolValue, It can’t have more than 1 BoolValue or less. So then if it’s 1 then it’ll finally damage the Humanoid.
if anticheat == "AntiCheat" then
local Bool = Instance.new("BoolValue", plr.Character:WaitForChild("CD"))
game.Debris:AddItem(Bool, HitboxSettings.Settings.DebounceTime / 1.25)
end
task.spawn(function()
local CooldownChildrens = plr.Character:WaitForChild("CD"):GetChildren()
if not plr.Character:WaitForChild("CD"):FindFirstChildOfClass("BoolValue") or #CooldownChildrens > 1 then
return plr:Kick("Kicked for trying to spam Hitboxes.")
end
end)
if plr.Character:WaitForChild("CD"):FindFirstChildOfClass("BoolValue") then
if hum then
print('Damaged.')
hum:FindFirstChildOfClass("Humanoid"):TakeDamage(HitboxSettings.Settings["Damage"])
end
end
That’s all of it now. For notice, this Hitbox is good to use for large / Slow Moving Objects. Otherwise, if you’re looking for a small Hitbox, it’s best to use RayCastParams, I’ll probably make one for it but not soon. Any feedback on this would help a lot, As I’m trying to get the best performance and as well easy to customize for you guys. Anyways, hope you enjoyed my tutorial as well my hitbox system!