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