Wave tweening Help

Im trying to make a object go from the humanoidrootpart of the player to another point, there is a erorr saying, Workspace.convert.LocalScript:16: invalid argument #1 to ‘new’ (Vector3 expected, got number) , the error is on the 5th line

				local PointA = Hit.Parent.HumanoidRootPart.Position
				local PointB = script.Parent.Model.bace.Position
				local Part = game.ReplicatedStorage.Woodpart:Clone()

				local Magnitude = (PointA - PointB).Magnitude

				local MidPosition = CFrame.new(PointA, PointB) * CFrame.new(0, 0, -Magnitude) * CFrame.new(-math.random(Magnitude / 2), math.random(Magnitude / 2)).Position -- the error is here

				local function Lerp(a, b, c)
					return a + (b - a) * c
				end

				local function QuadBezier (StartPosition, MidPosition, EndPosition, Offset)
					local L1 = Lerp(StartPosition, MidPosition, Offset)
					local L2 = Lerp(MidPosition, EndPosition, Offset)
					local QuadBezier = Lerp(L1, L2, Offset)

					return QuadBezier
				end

				for Index = 1, 10 do
					local CurrentPosition = QuadBezier(PointA, MidPosition, PointB, Index / 10)

					local PositionTween = game.TweenService:Create(Part, TweenInfo.new(.1), {Position = 
						CurrentPosition})

					PositionTween:Play()
					PositionTween.Completed:Wait()
				end
				

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

I think you have to use CFrame instead of Position for Vector3.Magnitude

I changed point A and point B to .CFrame isntead of .Posistion but now it is saying, Workspace.convert.LocalScript:14: invalid argument #2 (Vector3 expected, got CFrame), it still has the error on the same line

I’m not 100% sure, but I don’t think you can use PointA as a variable for the Vector3, you have to use the actual Vector3 in your Magnitude equation.

Just a coding suggestion for you: Try not to use capital letters for you Variables because it can cause confusion when reading through the code. For example in line 5 of your original code I would have put:
local magnitude = (PointA - PointB).Magnitude
The small letter helps distinguish the variable from an actual Magnitude when you use it later in your code.

You didn’t specify a value for the Z axis - that’s your 1st mistake, and your 2nd mistake is that you’re using the numeric Lerp function instead of the vector one.

local PointA = Hit.Parent.HumanoidRootPart.Position
local PointB = script.Parent.Model.bace.Position
local Part = game.ReplicatedStorage.Woodpart:Clone()

local Magnitude = (PointA - PointB).Magnitude

local MidPosition = (CFrame.new(PointA, PointB) * CFrame.new(0, 0, -Magnitude) * CFrame.new(-math.random(Magnitude / 2), math.random(Magnitude / 2), 0)).Position

local function Lerp(a, b, c)
	return a + (b - a) * c
end

local function QuadBezier(StartPosition: Vector3, MidPosition: Vector3, EndPosition: Vector3, Offset: number): Vector3
	local L1: Vector3 = StartPosition:Lerp(MidPosition, Offset)
	local L2: Vector3 = MidPosition:Lerp(EndPosition, Offset)
	local QuadBezier: Vector3 = L1:Lerp(L2, Offset)

	return QuadBezier
end

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