# Z is not a value of chunk

I am working on a chunk system for an infinite game, here is the script that when the player enters a new chunk, loads new chunks and destroys ones that are outside of the render distance.

ChunkPos is a vector2 Value of the chunk the player is in.

The render distance is set to 2 right now.

here is the function that creates the chunks and the X/Z int values that the first script checks (the variable C is useless, it’s for the brickcolor)

it works when you first spawn in, spawning the chunks around you. it also works fine when you walk in the Z direction, but when you cross a chunk in the X direction positive or negative, you get an error like this:

the Int values do exist, does anyone see something wrong? anything helps, thanks

2 Likes

Idk abt coding but isnt Vector2 for X&Y only? I think vector3 is for XYZ

3 Likes

yeah the chunks only load in the X and Z directions, so I only need a vector 2 for those values and not a vector3. I just use the Y part of the vector2 for the Z coordinate.

2 Likes

You can only get the x and z coordinates with a vector3. Vector2 is only for the x and y position on a 2d surface like the mouse on the players screen.

2 Likes

So its works like your mouse X and Y a 2d flat surface

2 Likes

Yes. If you were to get the players mouse and use mouse.Position it would return a vector2 value.

2 Likes

So this needs a vector3 script

2 Likes

Yes, It does need a vector3 value.

2 Likes

Maybe set it to Chunk.Y rather than X.

2 Likes

are you sure it is a member of the chunk folder? check it manually

2 Likes

They are using Vector2 not Vector3 thats why its buggy

2 Likes

I think the problem was a bit misunderstood, the chunks are sort of a grid-like 2d surface, layed out like Minecraft coordinates. the chunks don’t go in the Y direction so I used vector2 just as a variable to store two coordinates instead of having a useless Y value.

the solution (at least to this problem) was that in the first script, some chunks would trigger both if statements, and cause an error because the first statement would delete the chunk. I’m still working on a good way to delete all the necessary chunks, as that is a new problem.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.