I have a script that moves a part to the 3D position of a player's mouse cursor. In order to stop the cursor from following the camera, I decided to have the location of the part stop moving on a given access once the difference between the part and player exceeds a set range. However, I'm getting the error "attempt to perform arithmetic (sub) on Vector3 and number" whenever the range is exceeded. What should I do?
#How to fix "attempt to perform arithmetic (sub) on Vector3 and number" error?
1 messages · Page 1 of 1 (latest)
ts lowkey hard to read
magnitude seems to be a regular number
** You are now Level 10! **
yep
and you can minus numbers from a vector 3
The .Origin returns a vector if I remember correctly
yeah so it is a vector 3
so should i just do each axis individually
yh that's what I would try
probably a better way of going about it
but see if that works
try mp3dpos -= Vector3.new(distance.X * range, etc)
yeah i figured it out thanks to a forum post. the good news is no more syntax errors but the bad news is the cursor just disappears upon exceeding the range
i just want it to stop where it is upon exceeding the range
I'm not sure about what the maths behind that would be
ah kk
yeah theres def some formula i gotta get
thx for the help w the syntax error thing tho
no problem
string.split(vector3value,", ")[1]
well
you would do for i = 1,#string.split(vector3value,", ") do
then you would go like
im lying
just do vector3.New(string.split(vector3value,", ")[1],string.split(vector3value,", ")[2],string.split(vector3value,", ")[3])
that should do
it makes the string into a vector 3
wait
okay
ill write the whole script here
local vectortable = string.split(vectorvariable,", "
local x = vectortable[1]
local y = vectortable[2]
local z = vectortable[3]
-- do subtracting here
vector3.New(x,y,z)
boom
yourwelcome
50 robux pl;ease
wait
FUCK
local vectortable = string.split(vectorvariable,", "
local x = tonumber(vectortable[1])
local y = tonumber(vectortable[2])
local z = tonumber(vectortable[3])
-- do subtracting here
vector3.New
(x,y,z)
thats thew script that will work
replace vector variable with whatever u need
all in a days work
im a noob (5 days of scripting experience total) and have never seen this before, can you explain what this is and how it works plz?
vector 3 value is a string. you cannot subtract strings, so to subtract them we must use string.split,
tonumber turns the strings from string.split into numbers so they are subrtractable