UPDATE V4.0.1
- Added GetParts() method. @danipoplpl request
- Removed Client-Server Architecture
-
- Removed
UseClientparameter fromHitboxParamstype * RemovedClearHitboxesForClientstatic method since it’s no longer needed
- Removed
- All hitbox methods now work the same way on both client and server
Benefits
- You can now create client hitboxes directly without server involvement
- No more remote event overhead for client hitboxes
- You handle your own client-server communication if needed
Since EZ Hitbox now works identically on both client and server, you have full control over how to handle client-server communication. Here are some common patterns:
Pattern 1: Client Detection with Server Validation
-- Client Script
local Hitbox = require(path.to.Hitbox)
local ValidateHitRemote = ReplicatedStorage.ValidateHit
local hitbox = Hitbox.new({
SizeOrPart = Vector3.new(5, 5, 5),
DebounceTime = 0.1,
Debug = true
})
hitbox.OnHit:Connect(function(hitCharacters)
for _, character in ipairs(hitCharacters) do
-- Immediate client feedback
createHitEffect(character.HumanoidRootPart.Position)
-- Send to server for validation
ValidateHitRemote:FireServer(character, tick())
end
end)
-- Server Script
ValidateHitRemote.OnServerEvent:Connect(function(player, hitCharacter, timestamp)
-- Validate the hit on server
if isValidHit(player, hitCharacter, timestamp) then
-- Apply damage
local humanoid = hitCharacter:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid:TakeDamage(25)
end
end
end)
Pattern 2: Server-Only Detection
-- Server Script Only
local Hitbox = require(path.to.Hitbox)
local hitbox = Hitbox.new({
SizeOrPart = Vector3.new(5, 5, 5),
LookingFor = "Humanoid",
DebounceTime = 1.0
})
hitbox.OnHit:Connect(function(hitCharacters)
for _, character in ipairs(hitCharacters) do
-- Authoritative server detection
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid:TakeDamage(25)
-- Notify clients for effects
local player = Players:GetPlayerFromCharacter(character)
if player then
EffectsRemote:FireClient(player, "hit", character.HumanoidRootPart.Position)
end
end
end
end)