Hey! Im (kinda) a beginner scripter trying to make a fighting game. I am currently working on my Hitbox system and ive noticed it lags behind when the player moves (Which i dont want). Ive done some research but most of the solutions there uses welding parts to the player. My hitbox system dosent use parts and uses GetPartBoundsInBox instead so im not really sure what to do. What should I do to prevent my hitboxes from “lagging” behind? I really dont wanna rewrite my hitbox system.
local Remote = game.ReplicatedStorage:FindFirstChild("TestRemote")
Remote.OnServerEvent:Connect(function(player, attackType)
local char = player.Character
local HRP = char.HumanoidRootPart
if attackType == "M1 Normal" then
local hitboxPos = HRP.CFrame * CFrame.new(0,0,-3)
local filterObjects = {char}
local hitboxSize = Vector3.new(5,5,5)
local maxObjectsAllowed = 5
local params = OverlapParams.new(filterObjects,Enum.RaycastFilterType.Exclude,maxObjectsAllowed,"Default")
local hitObject = workspace:GetPartBoundsInBox(hitboxPos,hitboxSize,params)
local HitboxVisual = Instance.new("Part")
HitboxVisual.Anchored = true
HitboxVisual.CanCollide = false
HitboxVisual.CanQuery = false
HitboxVisual.CanTouch = false
HitboxVisual.CFrame = hitboxPos
HitboxVisual.Size = hitboxSize
HitboxVisual.Transparency = 0.5
HitboxVisual.Parent = game.Workspace
game.Debris:AddItem(HitboxVisual,0.25)
local hitPlayers = {}
for i,hit in pairs(hitObject) do
if hit.Parent:FindFirstChildOfClass("Humanoid") and hit.Parent.Name ~= player.Name and not table.find(hitPlayers, hit.Parent) then
table.insert(hitPlayers, hit.Parent)
hit.Parent.Humanoid.Health -= 10
print(hit.Parent.Humanoid.Health)
end
end
print(hitPlayers)
end
end)