Bezier curve soccer shooting not working well

I am doing a roblox soccer game and i am currently trying to make a shooting system using Bezier curves.
The problem is that the ball kinda moves in a bizarre way before reaching destination and sometimes bounces everywhere and falls of the game.
Everything else in th scripts works ,here is the script:

local event = game:GetService("ReplicatedStorage"):FindFirstChild("BezierCurve")
	if duration > 4 then duration = 4
	local a ="Part")
	local P1A ="Part")
	local b ="Part")
	a.Anchored = true
	P1A.Anchored = true
	b.Anchored = true
	a.CanCollide = false
	b.CanCollide = false
	P1A.CanCollide = false
	local ball = game.Workspace:FindFirstChild("Ball1")
	ball.Transparency = 0
	ball.a.Transparency =0
	ball.b.Transparency =0
	ball.c.Transparency =0
	ball.d.Transparency =0
	ball.f.Transparency =0
	a.Position = position +,0,0)
	local tDistanceY = duration* 20
	local X = MousePosition.x
	local Y = MousePosition.y
	local Z = MousePosition.z
	local bPosition =,Y,Z)
	b.Position = bPosition
	print("reached position mouse")
	P1A.Position = (bPosition + a.Position)/2 +,tDistanceY,0)
	print("mid position")
	local distance = (bPosition - a.Position).Magnitude
	local lerptime = (0.00525 * distance)/duration
	local function curve(t,P0,P1,P2)
		local A = P0:Lerp(P1,t)
		local B = P1:Lerp(P2,t)
		return A:Lerp(B,t)
		for i = 0,1,0.045 do
			local Bezier = curve(i,position,P1A.Position,bPosition)
		ball.Position = Bezier
		local waitime =  lerptime*0.045
		if i == 1 then

Here is what happens :
robloxapp-20230515-1745546.wmv (3.6 MB)

I have tried looking tutorials on beziercurves in the devforum and youtube but i still can’t fix it .
I also tried changing the collisions and the starting position.

i found that the reason is that there is the starting point and every time it moves it goes to the starting point and then the new one for an unknown reason but not only this sometimes it really moves randomly .

make sure to mark it as a solution

Now i really fixed by replacing the wait by task.wait() with nothing in brackets but i still want it to have a certain time

1 Like