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)