OverlapParam hitbox delay

I’m trying to create a simple hitbox, but there seems to be some kind of latency when I’m walking. It works perfectly fine when I’m still.

local

local remoteEvent = replicatedStorage:WaitForChild("RemoteEvent")

local tool = script.Parent

tool.Activated:Connect(function(player)
	remoteEvent:FireServer()
end)```
server
```local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = replicatedStorage:WaitForChild("RemoteEvent")
local hitBoxPart = replicatedStorage:WaitForChild("hitbox")

local overlapParams = OverlapParams.new()

remoteEvent.OnServerEvent:Connect(function(player)
	local hitList = {}
	local whiteList = {player.Character}
	
	overlapParams.FilterDescendantsInstances = whiteList
	
	local hrp = player.Character.HumanoidRootPart
	local hitBoxPosition = CFrame.new(0, 0, -2)
	local hitBoxSize = Vector3.new(4, 5, 3.5)
	local hitContents = workspace:GetPartBoundsInBox(hrp.CFrame * hitBoxPosition, hitBoxSize, overlapParams)
	
	local cloneOfHitboxPart = hitBoxPart:Clone()
	cloneOfHitboxPart.Parent = workspace
	cloneOfHitboxPart.Size = hitBoxSize
	cloneOfHitboxPart.CFrame = hrp.CFrame * hitBoxPosition
	
	for i, v in pairs(hitContents) do
		local parentV = v.Parent
		local humanoid = parentV:FindFirstChild("Humanoid")

		if humanoid then
			if not hitList[humanoid] then
				hitList[humanoid] = true
				humanoid:TakeDamage(10)
			end
		end
	end
	
	wait(1)
	cloneOfHitboxPart:Destroy()
	
end)```

This is because you’re creating the hitbox on the server. Movement is client authorative on Roblox (I believe), so therefore the Server isn’t as updated on the information of the player’s position as the client themselves are.

Which is why you’ll see the latency.

1 Like

Ah, thanks. Would FireAllClient be a better choice here?

Personally what I’d recommend is running the hitbox on the client itself, and then telling the server who was hit. Take into account their ping & their distance from the client itself. It’s obviously not perfect but if you want a solution with the least latency, this is probably your best bet.

Though if anyone had any ideas to improve that solution, please reply!

1 Like

This right here helps so much, not just with this hitbox, but why I see latency in my other scripts, thank you

1 Like