function PtoT(x,y,z)
if type(x) == “userdata” then
x,y,z = x.X,x.Y,x.Z
end
return Vector3.new(math.floor(x/b_size + .5)),Vector3.new(math.floor(y/b_size + .5)),Vector3.new(math.floor(z/b_size + .5))
end
It’s because you’re trying to add a number to a Vector3. It isn’t possible because a Vector3 data type has 3 properties/numbers, X, Y and Z respectively while a number only has one.
If you want to specify which property to add to (X, Y or Z), you need to create a new Vector3 with the number you wish to add in it. So for example if you wanted to add to the X.
-- Vector3(X, Y, Z)
local vector1 = Vector3.new(0,2,0)
print(vector1 + Vector3.new(5,0,0))
-- result: 5,2,0
function PtoT(x,y,z)
if type(x) == "userdata" then
x,y,z = x.X,x.Y,x.Z
end
return math.floor(x/b_size + .5),math.floor(y/b_size + .5),math.floor(z/b_size + .5)
end
function PtoT(x,y,z)
if type(x) == "userdata" then
x,y,z = x.X,x.Y,x.Z
end
return math.floor(x/b_size + .5),math.floor(y/b_size + .5),math.floor(z/b_size + .5)
end
I did not understand what you wrote, can you correct this error, here is the code
b_size = 3
function PtoT(x,y,z)
if type(x) == "userdata" then
x,y,z = x.X,x.Y,x.Z
end
return math.floor(x/b_size + .5),math.floor(y/b_size + .5),math.floor(z/b_size + .5)
end
Looks to be a type() problem, I guess? I changed type(x) == "userdata" to typeof(x) == "Vector3", and made 3 local variables that are the same as x, y, and z.
b_size = 3
function PtoT(x,y,z)
local X, Y, Z = x, y, z
if typeof(x) == "Vector3" then
X,Y,Z = x.X,x.Y,x.Z
end
return Vector3.new(math.floor(X/b_size + .5), 0, 0),
Vector3.new(0, math.floor(Y/b_size + .5), 0),
Vector3.new(0, 0, math.floor(Z/b_size + .5))
end