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)```