Attempt to perform arithmetic (add) on Vector3 and Instance

So I was reading up on Cubic and looking at models and I decided to make my own. Everything is going well but I come across this error; " ServerScriptService.CubicScript:33: attempt to perform arithmetic (add) on Vector3 and Instance - Server - CubicScript:33 " Im not sure how to solve this.


local CubicFire = game.ReplicatedStorage.CubicFire

local RunService = game:GetService("RunService")

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

function cubicBezier(t, p0, p1, p2, p3)
	local l1 = lerp(p0, p1, t)
	local l2 = lerp(p1, p2, t)
	local l3 = lerp(p2, p3, t)
	local a = lerp(l1, l2, t)
	local b = lerp(l2, l3, t)
	local cubic = lerp(a, b, t)
	return cubic
end

CubicFire.OnServerEvent:Connect(function(Player, Mouse)
	local Character = Player.Character
	local Root = Character:WaitForChild("HumanoidRootPart")

	local Start = os.clock()
	local Part = game.ReplicatedStorage.Part:Clone()
	Part.Parent = workspace
	Part.Anchored = true
	Part.CanCollide = false
	Part.Size = Vector3.new(1,1,1)
	Part.CFrame = Root.CFrame 
	local StartPosition = (Root.CFrame * CFrame.new(0,0,-5)).Position
	local Position3 = Mouse
	local Position1 = (StartPosition + Position3)/2 + Vector3.new(0,math.random(20,50),0)
	local Position2 = Position1 + Vector3.new(math.random(-40,40),0,math.random(-40,50))
	local Render; Render = RunService.Heartbeat:Connect(function()
		local End = os.clock() - Start

		Part.CFrame = CFrame.new(cubicBezier(End, StartPosition, Position1, Position2, Position3))
		if (End > 1) then
			Render:Disconnect()
			Part:Destroy()
		end		
	end)
end)

1 Like

Is the error on the line that has this:

local Position1 = (StartPosition + Position3)/2 + Vector3.new(0,math.random(20,50),0)

Yes thats the error and idk how to solve it. Its my first time coming up across it.

The variable Position3 is your parameter ‘mouse’:

Maybe use mouse.hit.p if you are not already doing that

I have a local script and the RemoteEvent is passing “mouse.hit.p” and in the server script I received it as Mouse. Ill use “mouse.hit.p” instead of “Mouse”.

You are trying to add a vector3 with the mouse object.

Use mouse.hit.p

"hit is not a valid member of Player “Players.IIRedRavenII” "

You’re probably doing something wrong with the Mouse parameter. Send over the position of the mouse. Something like this

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
game.ReplicatedStorage.CubicFire:FireServer(mouse.Hit.Position)

Can you do this:

print(typeof(Mouse))

And tell me what it says

It worked thanks! I had “CubicFire:FireServer(Player, mouse.Hit.Position)” so the script thought that the player is the mouse and the mouse is another variable that had nothing to do with it!

I solved it, thanks everyone for the help!