Hitbox is falling behind a moving player

I’m making my own hitbox for a game I am working on. I intend or the hitbox to do lock back to push people off a platform. The problem is when I summon the hitbox while the player is moving it lags behind instead of still being along with the player. Can anyone help? Also any recommendations on the rest of the script will help too.

local cooldown = false

game.ReplicatedStorage.PushRemote.OnServerEvent:Connect(function(plr)
	if not cooldown then
		cooldown = true

		local folder = Instance.new("Folder")
		folder.Name = plr.Character.Name.."'s Hitbox"
		folder.Parent = workspace

		local hb = Instance.new("Part")
		hb.Size = Vector3.new(4, 4.67, 3.12)

		local offset = Vector3.new(0, 0, -5)
		hb.CFrame = plr.Character.HumanoidRootPart.CFrame * CFrame.new(offset)

		hb.Parent = folder
		hb.Transparency = 0.5
		hb.CanCollide = false
		hb.CFrame = plr.Character.HumanoidRootPart.CFrame + Vector3.new(0,0,-3)

		hb.Touched:Connect(function(hit)
			local h = hit:FindFirstChild("Humanoid")
			if h and h.Parent ~= plr.Character then
				local bv = Instance.new("BodyVelocity")
				bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
				bv.Velocity = hb.CFrame.LookVector * 50
				bv.Parent = h.Parent.HumanoidRootPart
				wait(0.1)
				bv:Destroy()
			end
			wait(0.1)
			hb:Destroy()
		end)

		wait(1) 

		folder:Destroy()
		cooldown = false
	end
end)
3 Likes

I would probably stay away from BodyVelocity’s, and instead use welds. Body velocity’s aren’t meant to move things instantly, so the hitbox will always lag behind the player.
With welds the hitbox would be essentially attached to the player.

2 Likes

If I understand correctly what you’re trying to achieve, then the best way to make it work is by using Weld Constraint and applying Body Velocity to HumanoidRootPart located inside the character to push characters off the map.

The character moves wherever the HumanoidRootPart is located, and by using Body Velocity on it, the character will fly off as well.

Using Weld Constraint will weld the HitBox to the HumanoidRootPart, and it will never move away from it. The only thing is that you need to position the HitBox at the same location as the HumanoidRootPart only at the start and never later.

This should give you the desired system. If you have any questions, you can DM me on Discord at “joroka_”. I will gladly help you out.

here are some links that might assist you:

1 Like

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