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)
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)
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.