Hey everyone, I’m working on a hit detection system in my game, and I’m running into an issue where the hit detection seems to lag behind when the target is moving. Essentially, the hitbox appears to trail behind the actual position of the target, causing delayed or missed hits.
Here’s a video to visualize the issue:
Here is the code:
if (v.HumanoidRootPart.Position - RootPosition).Magnitude < Range then
Hit = true
ServerStorage.Tag:Fire(Character, v, Info)
end
I’m calling this module script function from an other module script called Activator which just does the combo logic and animations. and that activator is called from a server script as seen here:
Remotes.LeftClick.OnServerEvent:Connect(function(Player)
local Character = Player.Character
local Tool = Character:FindFirstChildWhichIsA("Tool")
if Tool and Tool:FindFirstChild("Activator") then
local WeaponStats = WeaponData.GetStats(Tool)
local Activator = require(Tool.Activator)
Activator.Active(Player, Character, Animations[WeaponStats.Type], Tool, WeaponStats)
end
end)
Any ideas how to make the eliminate the lag or other way to do this, I have tried to use RaycastHitboxV4 but the hitbox is too small for fast paced combat. any help will be appreciated.
Hi! There’s always a delay between client and server. It’s currently impossible to solve because of physics laws.
So you need to detect hit on client. I don’t understand your code, so here’s algorithm: LeftClick > Check if magnitude less than range > If it is then send data to server and deal damage
Wouldn’t the client be exposed to exploiters since they can access client side code. Would I just do a bunch of sanity checks on the server i.e is the player near the enemy, is the player alive etc.