Why am I getting this error?

Im trying to make a Dodgeball, by getting the players mouse position whenever the tool is activated, and then sending it through the Remote Event to the server.

But Im continuously getting this error, and Im not sure why.

  18:29:27.087  Workspace.Tool.Functionality:10: attempt to perform arithmetic (sub) on Instance and Vector3  -  Server - Functionality:10
  18:29:27.087  Stack Begin  -  Studio
  18:29:27.087  Script 'Workspace.Tool.Functionality', Line 10  -  Studio - Functionality:10
  18:29:27.087  Stack End  -  Studio

Here are the two scripts

local

local mouse = game.Players.LocalPlayer:GetMouse()

script.Parent.Activated:Connect(function()
	local mousePos = mouse.Hit.Position
	script.Parent:WaitForChild("RemoteEvent"):FireServer(mousePos)
end)

Server

local RemoteEvent = script.Parent:WaitForChild("RemoteEvent")

RemoteEvent.OnServerEvent:Connect(function(mousePos)
	local clonedBall = script.Parent:WaitForChild("Handle"):Clone()
	clonedBall.Parent = workspace
	clonedBall.Position = script.Parent:WaitForChild("Handle").Position
	
	local pos1 = script.Parent.Handle.Position
	local pos2 = mousePos
	local force = pos2 - pos1
	
	clonedBall:ApplyImpulse(force * clonedBall.AssemblyMass)
end)

First argument is always player. So you trying to subtract player with position. Simple fix is to add argument player before mousePos.

RemoteEvent.OnServerEvent:Connect(function(player,mousePos)

1 Like

I got this error

  18:43:39.709  Workspace.Tool.Functionality:10: attempt to perform arithmetic (sub) on Instance and Vector3  -  Server - Functionality:10
  18:43:39.709  Stack Begin  -  Studio
  18:43:39.709  Script 'Workspace.Tool.Functionality', Line 10  -  Studio - Functionality:10
  18:43:39.709  Stack End  -  Studio
RemoteEvent.OnServerEvent:Connect(function(plr, mousePos)
	local clonedBall = script.Parent:WaitForChild("Handle"):Clone()
	clonedBall.Parent = workspace
	clonedBall.Position = script.Parent:WaitForChild("Handle").Position
	
	local pos1 = script.Parent.Handle.Position
	local pos2 = mousePos
	local force = pos2 - pos1
	
	clonedBall:ApplyImpulse(force * clonedBall.AssemblyMass)
end)

Have you tried switching the variables and putting them on different sides?

That wouldn’t fix it at all, because the error is still saying that I am trying to subtract an Instance by a Vector, which Im not trying to do.

Im trying to subtract a vector by a vector, thats why when the tool gets activated, I make sure to get the players current mouse position ( mouse.Hit.Position ) and then I put it into the Remote Event so on a Server Event, the mousePosition ( which is a vector ) is supposed to be pos2.

Im not sure why it still say "Instance - Vector " though, because after firing the Remote, I sent in the mouse’s Position.

Maybe try to print pos2 and see what’s printing.

But I already know from the error that pos2 isn’t a vector value.

attempt to perform arithmetic (sub) on Instance and Vector3

The first argument in a :FireServer() is always the player therefore you are subtracting the player from a position I’ve fixed it down here:

local mouse = game.Players.LocalPlayer:GetMouse()

script.Parent.Activated:Connect(function()
	local mousePos = mouse.Hit.Position
	script.Parent:WaitForChild("RemoteEvent"):FireServer(player,mousePos)
end)
--**Server**

local RemoteEvent = script.Parent:WaitForChild("RemoteEvent")

RemoteEvent.OnServerEvent:Connect(function(player,mousePos)
local clonedBall = script.Parent:WaitForChild("Handle"):Clone()
	clonedBall.Parent = workspace
	clonedBall.Position = script.Parent:WaitForChild("Handle").Position
	
	local pos1 = script.Parent.Handle.Position
	local pos2 = mousePos
	local force = pos2 - pos1
	
	clonedBall:ApplyImpulse(force * clonedBall.AssemblyMass)
end)

If you want to check then print mousepos

where is this script ‘Functionality’? and whats the full script in it?