Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does my script print out nil for left and right and not for up and down?

I have a script that determines which grids is on the left, right, up, and down. The up and down grids work fine. But the right and left ones are just nil.

It might look like a lot of lines, so I organized it for y'all.

This is the serverscript:

local children  = game.Workspace.Grids:GetChildren()
local gridsfolder = game.Workspace.Grids

local GridRowID = script.Parent.RowID.Value

local currentgrid = script.Parent
local gridID = currentgrid:WaitForChild("GridID").Value
local typebuilding = currentgrid:WaitForChild("typebuilding").Value
local buildingorientation = currentgrid:WaitForChild("buildingorientation")

local direction
local GridOnTheRight
local GridOnTheLeft
local GridUp
local GridDown

local gridIDright = 0
local gridIDleft = 0
local gridIDup = 0
local gridIDdown = 0

gridIDright = gridID + 1
gridIDleft = gridID - 1
gridIDup = gridID - 5
gridIDdown = gridID + 5

local GridOnTheRightName = "Grid"..gridIDright
print(GridOnTheRightName)
for i,v in pairs(children) do
	if v:IsA("BasePart") and v.Name == GridOnTheRightName and v.RowID.Value == GridRowID then
		ridOnTheRight = v
	end
end

local GridOnTheLeftName = "Grid"..gridIDleft
print(GridOnTheLeftName)
for i,v in pairs(children) do
	if v:IsA("BasePart") and v.Name == GridOnTheLeftName and v.RowID.Value == GridRowID then
		GridOnTheleft = v
	end
end

local GridUpName = "Grid"..gridIDup
print(GridUpName)
for i,v in pairs(children) do
	if v:IsA("BasePart") and v.Name == GridUpName then
		GridUp = v
	end
end

local GridDownName = "Grid"..gridIDdown
print(GridDownName)
for i,v in pairs(children) do
	if v:IsA("BasePart") and v.Name == GridDownName then
		GridDown = v
	end
end

print("Right grid:", GridOnTheRight)
print("Left grid:", GridOnTheLeft)
print("Upper grid:", GridUp)
print("Lower grid:", GridDown)

Here is an image to better visualize what I mean with grids and directions etc.

This is the output:

Grid19

Grid17

Grid13

Grid23

Right grid: nil

Left grid: nil

Upper grid: Grid13

Lower grid: Grid23

1 answer

✓ Accepted answer

On Line 31: You misspelled GridOnTheRight as ridOnTheRight and on Line 39: You need to capitalise the l on GridOnTheleft.

This discussion is preserved as it was. New answers, comments, and votes are closed.