Making touch damage compensate with lag

Hi,

I’m having trouble with my hitbox damage having way too much reach or too little reach because of the players ping. If the person with the hitbox has really good ping and the other player has high ping, the other player sees himself being damaged from far away. A good example of this is Basketball Legends. You need to be in your own server location or it won’t be playable at all due to the hitbox issues.

However games like murders vs sheriff duels have lag compensation somehow. How would I do something similar to mvsd?

(serversided)

v.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid") :: Humanoid

	if not humanoid then
		return
	end

	local character = hit.Parent
	local player = Players:GetPlayerFromCharacter(character)
	local killer = Players:GetPlayerFromCharacter(v.Parent.Parent)

	if recentlyDamagedCharacters[character] then
		return
	end

	if ReplicatedStorage.Game:GetAttribute("Text") == Settings.RunnerWinStatus then
		return
	end

	if not player then return end

	local Damage = v:GetAttribute("Damage") or 0

	if player.Team and player.Team == Settings.Green then
		recentlyDamagedCharacters[character] = true
		Damage += Settings.RangeDamage
		humanoid:TakeDamage(Settings.RangeDamage)
		local newBlood = Blood:Clone()

		for _, instance in pairs(newBlood:GetChildren()) do
			local root = player.Character.HumanoidRootPart

			if instance:IsA("ParticleEmitter") then
				instance = instance :: ParticleEmitter

				instance.Parent = root
				instance:Emit(instance:GetAttribute("EmitCount"))
			end

			if instance:IsA("Sound") then
				instance = instance :: Sound
				PlaySound(instance, root)
			end
		end

		wait(Settings.RangeCooldown)

		recentlyDamagedCharacters[character] = nil
	end
end)
1 Like
  1. Don’t use the touched event for hit boxes. Instead, use something like GetPartBoundsInBox or GetPartsInPart
  2. You should probably perform do the hitbox stuff on the attackers side, send it to the server, and then verify the information. For example, you could do distance checks to see if the attacker was close enough to hit the attacker. (This is for close combat / non projectile things)

Actually, whats your hitbox for? Swords? Projectiles? Fighting/close combat?

2 Likes

Similar to swords. Basically I weld this mesh onto the players head and when they get close to someone, it hurts them.

1 Like

You should check out the public RayCastHitBox module, it’s one of the fastest available and is super good on resources.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.