"attempt to call a nil value" with a ModuleScript

EDIT: It turns out that I actually figured it out:

local findTiles = require(game.ReplicatedStorage.ModuleScripts.FindTiles)

function Detect()
	for _, tile in script.Parent.Parent.Tiles:GetChildren() do
		for _, Attachment in tile:GetChildren() do
			if Attachment.Name:find("DetectorTop") then
				local target = findTiles.LookForAdjacents(Attachment, Attachment.WorldPosition)
				if target ~= nil then
					local CountedBy = Instance.new("ObjectValue",target.Parent.AdjacentsAndStackers)
					CountedBy.Name = "StackedOnTopOf"..tile.Name..tile:GetAttribute("TileNumber")
					CountedBy.Value = tile
					local Blocker = Instance.new("ObjectValue")
					Blocker.Name = "StackingTile"
					Blocker.Value = target.Parent
					local RemoveIfCleared = script.Script:clone()
					RemoveIfCleared.Disabled = false
					RemoveIfCleared.Parent = Blocker
					local Cleared = Instance.new("BoolValue",RemoveIfCleared)
					Cleared.Name = "Cleared"
					Blocker.Parent = tile.Mechanics.StackingTiles
				end
			elseif Attachment.Name:find("DetectorLeft") then
				if script.Parent.GamemodeRules.BlockTilesOnLeftAndRight.Value == true then
					local target = findTiles.LookForAdjacents(Attachment, Attachment.WorldPosition)
					if target ~= nil then
						local CountedBy = Instance.new("ObjectValue",target.Parent.AdjacentsAndStackers)
						CountedBy.Name = "ToTheLeftOf"..tile.Name..tile:GetAttribute("TileNumber")
						CountedBy.Value = tile
						local Blocker = Instance.new("ObjectValue")
						Blocker.Name = "LeftAdjacentTile"
						Blocker.Value = target.Parent
						local RemoveIfCleared = script.Script:clone()
						RemoveIfCleared.Disabled = false
						RemoveIfCleared.Parent = Blocker
						local Cleared = Instance.new("BoolValue",RemoveIfCleared)
						Cleared.Name = "Cleared"
						Blocker.Parent = tile.Mechanics.LeftAdjacentTiles
					end
				end
			elseif Attachment.Name:find("DetectorRight") then
				if script.Parent.GamemodeRules.BlockTilesOnLeftAndRight.Value == true then
					local target = findTiles.LookForAdjacents(Attachment, Attachment.WorldPosition)
					if target ~= nil then
					local CountedBy = Instance.new("ObjectValue",target.Parent.AdjacentsAndStackers)
					CountedBy.Name = "ToTheRightOf"..tile.Name..tile:GetAttribute("TileNumber")
					CountedBy.Value = tile
					local Blocker = Instance.new("ObjectValue")
					Blocker.Name = "RightAdjacentTile"
					Blocker.Value = target.Parent
					local RemoveIfCleared = script.Script:clone()
					RemoveIfCleared.Disabled = false
					RemoveIfCleared.Parent = Blocker
					local Cleared = Instance.new("BoolValue",RemoveIfCleared)
					Cleared.Name = "Cleared"
					Blocker.Parent = tile.Mechanics.RightAdjacentTiles
				end
			end
		elseif Attachment.Name:find("DetectorFront") then
			if script.Parent.GamemodeRules.BlockTilesOnFrontAndBack.Value == true then
				local target = findTiles.LookForAdjacents(Attachment, Attachment.WorldPosition)
				if target ~= nil then
					local CountedBy = Instance.new("ObjectValue",target.Parent.AdjacentsAndStackers)
					CountedBy.Name = "Behind"..tile.Name..tile:GetAttribute("TileNumber")
					CountedBy.Value = tile
					local Blocker = Instance.new("ObjectValue")
					Blocker.Name = "FrontAdjacentTile"
					Blocker.Value = target.Parent
					local RemoveIfCleared = script.Script:clone()
					RemoveIfCleared.Disabled = false
					RemoveIfCleared.Parent = Blocker
					local Cleared = Instance.new("BoolValue",RemoveIfCleared)
					Cleared.Name = "Cleared"
					Blocker.Parent = tile.Mechanics.FrontAdjacentTiles
				end
			end
		elseif Attachment.Name:find("DetectorBack") then
			if script.Parent.GamemodeRules.BlockTilesOnFrontAndBack.Value == true then
				local target = findTiles.LookForAdjacents(Attachment, Attachment.WorldPosition)
				if target ~= nil then
					local CountedBy = Instance.new("ObjectValue",target.Parent.AdjacentsAndStackers)
					CountedBy.Name = "InFrontOf"..tile.Name..tile:GetAttribute("TileNumber")
					CountedBy.Value = tile
					local Blocker = Instance.new("ObjectValue")
					Blocker.Name = "BackAdjacentTile"
					Blocker.Value = target.Parent
					local RemoveIfCleared = script.Script:clone()
					RemoveIfCleared.Disabled = false
					RemoveIfCleared.Parent = Blocker
					local Cleared = Instance.new("BoolValue",RemoveIfCleared)
					Cleared.Name = "Cleared"
					Blocker.Parent = tile.Mechanics.BackAdjacentTiles
					end
				end
			end
		end
		tile.Mechanics.DetectAdjacentsAndStackers.Detect:Fire()
		tile:SetAttribute("IsLoaded",true)
		tile.Mechanics.Owner.Value.Mechanics.TilesLoaded.Value = tile.Mechanics.Owner.Value.Mechanics.TilesLoaded.Value + 1
		tile.SelectScript.Disabled = false
		tile.Mechanics.FindPairs.Event:Fire()
	end
end

script.Event.Event:connect(Detect)
local module = {}

function module.LookForAdjacents(att, pos)
	local list = att.Parent.Mechanics.Owner.Value.Tiles:GetChildren()
	local tile = nil
	local dist = .5
	local temp = nil
	local temp2 = nil
	for x = 1, #list do
		temp2 = list[x]
		if (temp2.Name:find("Tile")) and (temp2 ~= att.Parent) then
			temp = temp2:FindFirstChild("RootAttachment")
			if (temp ~= nil) and (temp.WorldPosition - pos).magnitude < dist then
				tile = temp
				dist = (temp.WorldPosition - pos).magnitude
			end
		end
	end
	return tile
end

return module

I must’ve forgotten to add module. first before LookForAdjacents(att, pos)

I even added (att, pos) in place of (pos). My bad.

2 Likes

ok cool so it was this value not being able to be found right
glad to see you got it fixed