Alright well, I have been tilted on this same error but it doesn’t make sense at all, hopefully, one of you see the fix?
So here is the error: attempt to perform arithmetic (add) on nil and number
Standard error right? Should be easy.
Well here it is.
local position = Vector3.new(start.X + x/2,start.Y,start.Z + z/2)
Now here is the funny part. I print those equations it works fine! and the code works fine, until I do the following:
local position = Vector3.new(start.X + x/2,start.Y,start.Z + z/2)
positions[i][1] = position -- this is table.
Everything works fine until I add it to the table.
Really lost here, not sure if I am tilted and can’t see it, but I have taken breaks and still confused.
ItzBloxyDev
(ItzBloxyDev)
September 2, 2022, 11:18pm
#2
what line is the error on, can you show the whole code maybe? one of the variables is probably nil
What is the “i” variable referencing?
SpiralAPI
(arlo)
September 2, 2022, 11:21pm
#4
local positions = Vector3
, not a table.
positions[i][1]
wouldn’t work because Vector3[1]
isnt possible.
Edit: Nevermind just saw you editted it.
1 Like
Sorry, that was an issue on my part, in the actual code it doesn’t show that.
1 Like
i is the index in the for loop
local positions = {}
local start = Vector3.new(zone.Position.X - (x/2), zone.Position.Y, zone.Position.Z - (z/2))
print(start.X + x/2, start.Z + z/2)
print(x/2, z/2)
for i = 1, split_into do
local position = Vector3.new(start.X + x/2,start.Y,start.Z + z/2)
positions[i] = {}
positions[i][1] = position
if long == x then
positions[i][2] = Vector3.new(long, 0, 0)
else
positions[i][2] = Vector3.new(0, 0, long)
end
start = positions[i]
end
Vector3s are indexed using strings, like “X”, “Y”, or “Z”
noahrepublic:
positions = {}
You redefine the table and make it blank during every iteration
sorry edited that in, meant to put
positions[i] = {} either way, that isn’t where the error is.
noahrepublic:
start = positions[i]
Here, you redefine start
as a table and not a Vector3, which is not what your code is expecting
goodness, looks like a i was tilted, thanks a lot, just needed a new set of eyes on the problem!