Dictionaries returning nil?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    Hi, I’m developing a gnarly (cool even) world generation that generates pillars on based on a vector position, with varying heights ecte ct. Basically it’s pillars being generated out of 2 pillars which are
    a pillar
    and a not pillar (a pillar but with nocollide and transparent)

This is my code so far!

local Plates = game.ReplicatedStorage.Places:GetChildren()
local x = -25
local z = -25

local PlatePos = {}

for count = 1,50 do
	
	for count2 = 1,50 do
		local PlateSpawn = Plates[math.random(1,#Plates)]:Clone()
		PlateSpawn.Primary.Position = Vector3.new(x * 200, math.random(-50,50), z * 200)
		PlateSpawn.Parent = game.Workspace.Plates
		PlatePos[Vector2.new(x, z)] = PlateSpawn
		x += 1
	end
	x = -25
	z += 1
end

x = -25
y = -25
print(PlatePos)

for count = 1,50 do
	for count2 = 1,50 do
		local BasePlate = PlatePos[Vector2.new(x,y)]
		if BasePlate.bridge == true then
			BasePlate.bridgegenerated = true
			local BridgingPlate = PlatePos[Vector2.new(x - 1, y)]
			if BridgingPlate.bridge == true and BridgingPlate.bridgegenerated == false then
				local BridgePart = game.ReplicatedStorage.BridgePart:Clone()
				BridgePart.Size = Vector3.new((BridgingPlate - BasePlate).Magnitude, 24, 150)
				BridgePart.CFrame = Vector3.new(BasePlate.Primary.Position, BridgingPlate.Primary.Position)
				BridgePart.Parent = game.Workspace
			end
		end
		x += 1
	end
	x = -25
	z += 1
end
  1. What is the issue?
    I am getting an error! This is the error:
 ServerScriptService.Scripts.Generate:27: attempt to index nil with 'bridge'

I’m pretty new to dictionaries though, I almost expected it to go wrong - I’m just not sure how to fix it.

  1. What solutions have you tried so far?
    I have a pretty good coding friend who also couldn’t find out what was going on. I know that somehow BasePlate is nil, I just dont understand how.
local Table = {
    [Vector2.new(50, 50)] = 50
}

print(Table[Vector2.new(50, 50)])
-- ouput

nil

basically you can’t access Vector2 indexes this way(works with Vector3 tho)

local Plates = game.ReplicatedStorage.Places:GetChildren()
local x = -25
local z = -25

local PlatePos = {}

for count = 1,50 do
	
	for count2 = 1,50 do
		local PlateSpawn = Plates[math.random(1,#Plates)]:Clone()
		PlateSpawn.Primary.Position = Vector3.new(x * 200, math.random(-50,50), z * 200)
		PlateSpawn.Parent = game.Workspace.Plates
		PlatePos[tostring(Vector2.new(x, z))] = PlateSpawn
		x += 1
	end
	x = -25
	z += 1
end

x = -25
y = -25
print(PlatePos)

for count = 1,50 do
	for count2 = 1,50 do
		local BasePlate = PlatePos[tostring(Vector2.new(x, z))]
		if BasePlate.bridge == true then
			BasePlate.bridgegenerated = true
			local BridgingPlate = PlatePos[tostring(Vector2.new(x - 1, y))]
			if BridgingPlate.bridge == true and BridgingPlate.bridgegenerated == false then
				local BridgePart = game.ReplicatedStorage.BridgePart:Clone()
				BridgePart.Size = Vector3.new((BridgingPlate - BasePlate).Magnitude, 24, 150)
				BridgePart.CFrame = Vector3.new(BasePlate.Primary.Position, BridgingPlate.Primary.Position)
				BridgePart.Parent = game.Workspace
			end
		end
		x += 1
	end
	x = -25
	z += 1
end

with that in mind we can use tostring() to access the Vector2 indexes easily