I’m making a melee system that uses RaycastHitbox on the CLIENT-SIDE to achieve more fast and accurate raycasts, I was just wondering if there is a better way to prevent exploiters from attacking too fast on the server. I feel like my method is too complex/im doing something wrong.
local hitTargets = {}
local lastHit = os.clock()
local isAttacking = false
local function onHitEvent(player: Player, hitPart: BasePart)
print(player, hitPart)
if not validateHit(player, tool, hitPart) then
warn(`Failure to validate hit {player.Name}`)
return
end
local hitCharacter = hitPart.Parent
if hitPart.Name == "Handle" and hitPart:FindFirstAncestorWhichIsA("Accessory") then
hitCharacter = hitPart.Parent.Parent
end
local hitHumanoid = hitCharacter:FindFirstChild("Humanoid")
local hitPlayer = Players:GetPlayerFromCharacter(hitCharacter)
local hitHumanoidRootPart = hitCharacter:FindFirstChild("HumanoidRootPart")
if hitPlayer then
local isRagdoll = hitCharacter:FindFirstChild("IsRagdoll")
isRagdoll.Value = true
local bodyVelocity = Instance.new("BodyVelocity", hitHumanoidRootPart)
bodyVelocity.Velocity = player.Character.PrimaryPart.CFrame.LookVector * 20
task.delay(Configuration.RAGDOLL_DURATION * 0.2, function()
bodyVelocity:Destroy()
end)
task.delay(Configuration.RAGDOLL_DURATION, function()
isRagdoll.Value = false
end)
end
if not hitHumanoid or hitTargets[hitHumanoid] then
return
end
if not isAttacking and math.abs(os.clock() - lastHit) >= Configuration.ATTACK_DURATION then
isAttacking = true
lastHit = os.clock()
task.delay(Configuration.ATTACK_DURATION, function()
isAttacking = false
hitTargets = {}
end)
end
if isAttacking then
hitHumanoid:TakeDamage(Configuration.DAMAGE)
hitTargets[hitHumanoid] = true
end
end