Basketball Velocity Freezing

  1. What is the issue? Include screenshots / videos if possible!
    Okay so i have a basket system in my game where u press e and it shoots the ball into the hoop
    but for some reason whenever it gets close to the hoop it completely freezes for a split second then finishes
    https://gyazo.com/b5ec37e4a5b1aa46d96a7bdd5049490c

here is the script

script.Parent.OnServerEvent:Connect(function(player, SPos, ShootMeter,load)
	local alreadyhit = false
	local Hoop1 = workspace.Hoop1
	local hrp = player.Character.HumanoidRootPart
	local isone = false
	
	local ball = 1
	local hrp = player.Character.HumanoidRootPart
	for i,v in pairs(workspace:GetChildren()) do
		if v.Name == "B-Ball" and v:FindFirstChild(player.Name) then
			ball = v
			ball:WaitForChild(player.Name):Destroy()
		end
	end
	
	hrp.BallJoint:Destroy()
	ball:SetNetworkOwner(nil)
	
	local hrpPos = hrp.Position
	local shootspawn = rps.ShootSpawn:Clone()
	shootspawn.CFrame = hrp.CFrame * CFrame.new(0,3,-1)
	ball.CFrame = shootspawn.CFrame


	coroutine.wrap(function()
		for i = 0,55 do
			ball.CFrame = ball.CFrame * CFrame.fromEulerAnglesXYZ(-0.6,0,0)
			task.wait()
		end

	end)()
	local t = 1;
	local g = Vector3.new(0, - workspace.Gravity, 0);
	local x0 = shootspawn.CFrame * Vector3.new(0,0,0)

	-- calculate the v0 needed to reach mouse.Hit.p
	local v0 = (Hoop1.Position - x0 - 0.5*g*t*t)/t;

	-- have the ball travel that path
	ball.Velocity = v0;
	ball.CFrame = CFrame.new(x0);
	
	if (Hoop1.Position - SPos).magnitude < 1 and alreadyhit == false then
		wait(1)
		print("hit")
		workspace.Hoop1.Swish:Play()
		alreadyhit = true	
		script.Parent:FireClient(player)
	end
	if (Hoop1.Position - SPos).magnitude > 1 and (Hoop1.Position - SPos).magnitude < 1.7 and alreadyhit == false then
		wait(1)
		print("hit")
		workspace.Hoop1.rim:Play()
		alreadyhit = true	
		script.Parent:FireClient(player)
	end
	wait(0.2)
	isone = true
	script.Parent:FireClient(player,isone)
	wait(0.2)
	player.Backpack.Stuff.HasBall.Value = false
	player.Backpack.Stuff.Shooting.Value = false
	end)

things i already tried
changing the Network owner to server and player
turning the ball and hoop can collide off, even turned the other things in the court can collide off

even when i moved the part the pall goes to(when its shot) to a empty area of the map it still froze mid air

ive been tryna think of solutions for hours and none of them are working

This is probably the issue. If the network owner changes, the physics haults for a moment to let the closest user handle it’s physics. If you keep the network owner to the owner of the basketball, it will most likely fix the problem.

i had said i tried that already i tried setting it to player, server, and not even changing it at all and i get the same results

nvm, figured out the issue on my own

What was the solution to your problem? I’m curious.

Just a consideration, but if you want to have a smoother projectile motion consider updating the CFrame via on the Client and handling the Magnitude check on the server.

the loop script i had that was rotating the ball was ending to early so it caused the ball to freeze for a split second

it would be smoother but i think it would laggy when other people look at it

Actually it is highly recommended to run projectiles on the client, this is because you are allowed to use the RenderStepped function on the client which allows you to update the projectile CFrame (Or basketball in your case) prior the frame being rendered.

This post explains it well: Do I need to run my projectiles on the client?

	local t = 1;
	local x0 = ball.CFrame * Vector3.new(0,0,0)
	local g = Vector3.new(0, - workspace.Gravity, 0);
	local v0 = (SPos - x0 - 0.5*g*t*t)/t;
	ball.Velocity = v0;

this is the line of code that moves the ball
where exactly would i use the RenderStepped function

You would have to use the :FireAllClients when the ball is fired on the server.

You would then update the ball CFrame on the client via the RenderStepped function.

You will then have to handle the hit/magnitude check on the server to prevent any exploiters bypassing the system.

This is all pseudocode, if you want a more detailed explanation check out other posts on DevForum regarding this topic.

And obviously your system works fine, so feel free to ignore this. This is just more or less a more polished and smoother way to handle projectiles if that is what you are trying to accomplish.

i think im confused, wdym “update the balls CFrame” isnt the ball using velocity?

Oh sorry, I seemed to have misread your code above.

Normally I would update the projectile CFrame every frame for a more calculated motion and drop, but in your case you seem to use velocity so leaving on the server is fine actually.

Here’s a article (tutorial) of what I mean: Modeling a projectile's motion

He seems to calculate the trajectory on the server in the tutorial, but I still recommend to do it via the Client.

i actually had my old system do that before but i changed it to velocity since collisions where making the ball act weird(i have a system where u can miss shots so sometimes the basket ball would go inside the rim or get stuck on the net)

Let the client handle the ball travelin in air.
This is how I coded my release system…

	local function Release(Ball,HumanoidRootPart,Goal,Size,Percent)
		local Magnitude = (Ball.Position - Goal.Position).Magnitude;
		local Target = 1.1 + (Magnitude/110);
		local Gravity = Vector3.new(0,-workspace.Gravity/math.pi,0);
		local X0 = Ball.Position;
		local V0 = (Goal.Position - X0 - 0.5 * Gravity * Target * Target)/Target/1.045;
		local Offset = OffsetMath(Size,Percent);
		
		Ball.Connect.Part0 = nil;
		Ball.Parent = workspace;
		Ball.Velocity = V0 + Vector3.new(Offset,Offset,Offset);
		Ball.RotVelocity = Vector3.new(0,0,25);
		wait(Count);
		Ball:SetAttribute('Parent','');
	end;