Grid System using Vector2's and assigning number values to each grid point

local XIncrement, XLength = 21, 21 * 5
local ZIncrement, ZLength = 21, 21 * 5

local MapValues  = {}
local Map = {}

-- making the table
for X = 0, XLength, XIncrement do
	for Z = 0, ZLength, ZIncrement do
		table.insert(Map, Vector2.new(X, Z))
		MapValues[Vector2.new(X, Z)] = {
			1	-- this is the value of the gridpoint
		}
	end
end

--assigning random traps

local RandomCoordinate = MapValues[Map[math.random(#Map)]]


for randospot = 0, 5, 1 do
	RandomCoordinate = MapValues[Map[math.random(#Map)]]
	print(RandomCoordinate)
end

So I am basically trying to make a grid (players can’t interact with the grid). I made a 6x6 grid starting from the origin and each grid being 21 studs long (square). I want to choose random grid spots and read their value, which should of been set to β€œ1”. This only prints nil (x6).

2 Likes

Nvm I figured it out. Just had to do randomcoordinate.x and randomcoordinate.y

1 Like

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