Ball lag in basketball game when shooting

So im making a basketball game and i have a bug ive been struggling with for a while, basically, i have a net made of rope constraints for a swish effect when making shots, it works but causes lag when shooting the ball because the ball using physics for shooting. This is my shooting event:

ShootEvent.OnServerEvent:Connect(function(plr, GoalPart, Percent, ShotType, ball)
	if ball then
		ball:SetNetworkOwner(plr)
		ball.BallWeld.Part0 = nil
		ball.Parent = workspace.Basketballs
		ball.CanCollide = false
		ball.CanTouch = false
		local MagnitudeNew = (plr.Character.HumanoidRootPart.Position-GoalPart.Position).Magnitude
		local Trajectory = 1.1 + (MagnitudeNew/110)
		local Gravity = Vector3.new(0, -workspace.Gravity, 0)
		local X0 = ball.Position
		local V0 = (GoalPart.Position - X0 - ShotType * Gravity * Trajectory * Trajectory) / Trajectory
		if Percent >= 0.98 then
			ball.Velocity = V0
		else
			local errorAmount = (1 - Percent) * 3

			local randomX = (math.random() - 0.5) * errorAmount
			local randomZ = (math.random() - 0.5) * errorAmount

			local horizontalError = Vector3.new(randomX, 0, randomZ)

			ball.Velocity = V0 + horizontalError
		end

		task.wait(0.3)
		ball.CollisionGroup = "Ball"
		ball.CanTouch = true
		ball.CanCollide = true
	end
end)

and what happens is the ball can freeze when getting close to the net. Ive already tried to set the network owner, and also put the net on the client, but i still have the issue. This is what it looks like in game


This example isnt the best because it usally lags more, especialy when theres more people in the game

Hey XPK_YT12!

I am not the most experienced scripter when it comes to the physics engine, I have not done much with it nor put a lot of time in to researching it. But I believe the physics engine can cause lag for a variety of different reasons, one are physics aren’t rendered at 60Hz so there can be laggy or not so smooth physics in general.

I believe for this, it acts as a projectile and therefore could use a loop which updates the CFrame along a trajectory’s path. This might be better in terms of smoothness and lag. If this does not work well with your net, you could possibly come up with a different solutions for your net effect or this solution might not just be for you. Like I said, I am not experienced in the physics engine, but I will always try to help!

Sincerely,
ModzZealous

Hey, I’ve worked on a few basketball games, and you should use a mesh net and SmartBone module instead of constraints. I actually have an extra you can have, dm me I’ll give you my discord. It’s very easy to set up and doesn’t lag at all
It is the only good way to do this

Oh I replied to the wrong person sorry

this is what smartbone looks like in a net.
much smoother. constraints are just too laggy for more than 1 net

Well that’s the reason not to run urgent requests and trajectory calculations on the server. Because there’s massive network delay. What you should do is use fake visual balls that are calculated on the client. Server sends relay positions, (packets sent through 20-60 times) under calculations and control. During these 16 miliseconds we can use a formula of
predicted = projectile position current + (velocity * delta time). It’s like this we send a packet in 50 ms, the server gets that packet, but lags behind due to refresh rate and network delay, and processes of mathematics.

However, using this we can just send one packet, then server initiates and confirms, and sends you the position till the end of the parabola (real ball is invisible, but moves using physics in server, server sends that position, and client registers, and predicts the next position )I think this is the way to do it.

For disabling collision, you could use PhysicsService to register the real ball as ignore collision to the nets.