Needing help to make the hitbox moving with the player better

So… making a new version of an hitbox script, but i have a problem with making it move with the player without making it leave behind. Can somebody help me fixing this? Thank you for your help and answer.

Server Script (in serverscriptservice):

local replicated = game:GetService("ReplicatedStorage")
local part = replicated.Hitbox
local eventfolder = replicated.AttackEvents
local AttackRemote = eventfolder.Attack
local soundservice = game.SoundService
local attacksounds = soundservice.AttackSounds
local Tribute = attacksounds.Tribute
local Attack1 = Tribute.Attack1
local Attack2 = Tribute.Attack2

AttackRemote.OnServerEvent:Connect(function(player)
	print("test")
	local clone = part:Clone()
	Attack1.Parent = player.Character.HumanoidRootPart
	Attack2.Parent = player.Character.HumanoidRootPart
	Attack1:Play()
	Attack2:Play()
	clone.Parent = workspace
	clone.Position = player.Character.HumanoidRootPart.Position
	for counter = 1, 0, -0.1 do
		clone.Position = player.Character.HumanoidRootPart.Position
		wait(0.1)
	end
	wait(0.4)
	clone:Destroy()
end)```

Put a weld constraint into the Hitbox to attach it to the HumanoidRootPart

1 Like

Tried to do it, but there’s a problem that the player strangely teleports to the part:


Any idea how to fix it?

The new version of the script:

local replicated = game:GetService("ReplicatedStorage")
local part = replicated.Hitbox
local eventfolder = replicated.AttackEvents
local AttackRemote = eventfolder.Attack
local soundservice = game.SoundService
local attacksounds = soundservice.AttackSounds
local Tribute = attacksounds.Tribute
local Attack1 = Tribute.Attack1
local Attack2 = Tribute.Attack2

AttackRemote.OnServerEvent:Connect(function(player)
	print("test")
	local clone = part:Clone()
	local weldcontraint = Instance.new("WeldConstraint")
	Attack1.Parent = player.Character.HumanoidRootPart
	Attack2.Parent = player.Character.HumanoidRootPart
	Attack1:Play()
	Attack2:Play()
	clone.Parent = workspace
	clone.Position = player.Character.HumanoidRootPart.Position
	clone.CanCollide = false
	weldcontraint.Parent = clone
	weldcontraint.Part0 = clone
	weldcontraint.Part1 = player.Character.HumanoidRootPart
	wait(0.4)
	clone:Destroy()
end)
1 Like

That is lag my friend. Specifically your network ping.

Using an unreliable re and passing the client’s version of your position will look better to you but weird for everyone else.

Dont do what the guy said. Weld constraints with hitboxes wont fix much. The reason the hitbox goes behind you is due to latency. If you want to fix that you have to add an offset of the player’s rootpart’s velocity * 0.175. See if that fixes it.

1 Like

This is just caused by ping. It’s very common for hitboxes to lag behind slightly in competitive games, otherwise very laggy people would have a big upper hand since they can hit people if their game freezes.

So, if you’re making a pvp game, this is pretty normal and it isn’t something you should really worry about. On the other hand, if you’re making a PVE game, then you should make the hitboxes start on the client then send over the hitbox info to the server, where the server does several checks before applying the damage to double check that the player isnt exploiting

1 Like

So… added a CFrame and combined the clone position with the Velocity. I think i’m getting a little bit closer, thx for the help.

local replicated = game:GetService("ReplicatedStorage")
local part = replicated.Hitbox
local eventfolder = replicated.AttackEvents
local AttackRemote = eventfolder.Attack
local soundservice = game.SoundService
local attacksounds = soundservice.AttackSounds
local Tribute = attacksounds.Tribute
local Attack1 = Tribute.Attack1
local Attack2 = Tribute.Attack2

AttackRemote.OnServerEvent:Connect(function(player)
	print("test")
	local clone = part:Clone()
	local char = player.Character
	local root = char:WaitForChild("HumanoidRootPart")
	local rootvelocity = root.Velocity
	Attack1.Parent = player.Character.HumanoidRootPart
	Attack2.Parent = player.Character.HumanoidRootPart
	Attack1:Play()
	Attack2:Play()
	clone.Parent = workspace
	clone.CFrame = player.Character.HumanoidRootPart.CFrame
	clone.Position = player.Character.HumanoidRootPart.Position
	for counter = 1, 0, -0.1 do
		clone.Position = player.Character.HumanoidRootPart.Velocity * 0.175 + player.Character.HumanoidRootPart.Position
		clone.CFrame = player.Character.HumanoidRootPart.CFrame
		wait(0.01)
	end
	clone:Destroy()
end)
1 Like

wrong video:

Due to ping your hitbox appears, to your client, to lag behind where you actually are. Ideally, you need to do the initial hitbox detection on the client.

Create the hitbox with a localscript and handle the detection there (whether you use .Touched or :GetPartsInPart() is up to you) - then once you have successfully hit something, trigger a RemoteEvent on the server with the hit data.

When the server receives a successful hit, it’s paramount that you then do some basic checks whether this hit that the client deems as valid is actually valid. E.g. how close is the hit to the player character. (Avoid exploiters just hitting people from across the map)

So i just need to combine these scripts? Just asking

cuz dunno if the damage thing would work since it should be for an Asym game

That is not his “lag”, he is testing locally. The reason the hitbox is a bit behind Roblox only replicates at 20-30Hz rate. But of course lag can make it worse.

Either do client-sided hitboxes and do validations on server or try spawning the hitbox on server 1 stud further in front of the character (this is probably bad, but it just randomly came to mind lol)

Hitbox:SetNetworkOwner(player)
Super good server anticheat

So… what does this script do? Just asking

Nothing, hes a ragebaitter don’t listen to him, check my answer above his

Why post at all if you just want to troll

Ig ima close this post. Thank you guys for your help

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