20:41:54.976 cloud_5630413655.obfscrpt:1: invalid argument #1 to 'pairs' (table expected, got nil) - Client

Hi there! I’m having a very odd issue with my code where I am constantly getting an error from a script I cannot see that a table being inputted into a pairs function is nil. I don’t understand why I am getting this code as it seems arbitrary based on what code I have regardless if it affects the table for the in pairs loop or not.

Here is the affected code:

local TangentPath = require(workspace.Objects.TangentPath)

local W = workspace.Wheels
local EX = workspace.Ex

local tE = {}

tE[1] = {TangentPath.new(W["1"],W["2"],1),EX:Clone(),EX:Clone()}
tE[2] = {TangentPath.new(W["2"],W["3"],1),EX:Clone(),EX:Clone()}
tE[3] = {TangentPath.new(W["3"],W["4"],1),EX:Clone(),EX:Clone()}
tE[4] = {TangentPath.new(W["4"],W["5"],1),EX:Clone(),EX:Clone()}
tE[5] = {TangentPath.new(W["5"],W["6"],1),EX:Clone(),EX:Clone()}
tE[6] = {TangentPath.new(W["6"],W["7"],-1),EX:Clone(),EX:Clone()}
tE[7] = {TangentPath.new(W["7"],W["8"],-1),EX:Clone(),EX:Clone()}
tE[8] = {TangentPath.new(W["8"],W["9"],-1),EX:Clone(),EX:Clone()}
tE[9] = {TangentPath.new(W["9"],W["1"],-1),EX:Clone(),EX:Clone()}

for i,v in pairs(tE) do
	v[2].Parent = workspace.Points
	v[3].Parent = workspace.Points

	v[4] = Instance.new("Part")
	v[4].Parent = workspace.Points
	v[4].Anchored = true
	v[4].Size = Vector3.new(0.2,0.2,0.2)
end

game:GetService("RunService").RenderStepped:Connect(function()
	for i,v in pairs(tE) do
		v[1]:update()
		v[2].CFrame = v[1].pos1
		v[3].CFrame = v[1].pos2
	end
end)

TangentPath is an object that takes two cylinders and finds a point of tangency to both cylinders to connect them. It does not use any for loops at all, but whenever one of they cylinders are moved it throws this error even though the code still works fine

This is the TangentPath module

local TPath = {}
TPath.__index = TPath

function TPath.new(p1 : Part, p2: Part, yMod: number)
	local self = {}
	setmetatable(self, TPath)
	
	self.p1 = p1
	self.p1rad = p1.Size.Y/2 -- Store the radius of the 1st part
	self.p2 = p2
	self.p2rad = p2.Size.Y/2 -- Store the radius of the 2nd part
	
	self.pos1 = CFrame.new(0,0,0) -- The world position of the tangent point on p1
	self.pos2 = CFrame.new(0,0,0) -- The world position of the tangent point on p2
	
	self.yMod = yMod -- This determines which solution, up or down, is favoured. SHOULD ONLY BE -1 OR 1
	
	return self
end

function TPath:update()
	-- X difference can be assumed to be zero for the calculations (assume they are along the same plane)
	local p1cf = self.p1.CFrame
	local p2cf = self.p2.CFrame
	
	local diff = p1cf:ToObjectSpace(p2cf) -- Get difference in position between the wheels
	local y = diff.Y
	local z = diff.Z
	
	local angle = math.atan(y/z) -- angle between the two wheels
	
	local z1Off = self.p1rad*math.sin(angle) -- left/right offset for the tangent point on p1
	local y1Off = self.p1rad*math.cos(angle) -- up/down offset for the tangent point on p1
	local z2Off = self.p2rad*math.sin(angle) -- L/R off for p2
	local y2Off = self.p2rad*math.cos(angle) -- U/D off for p2
	
	self.pos1 = p1cf:ToWorldSpace(CFrame.new(0,y1Off*self.yMod,-z1Off*self.yMod))
	self.pos2 = p2cf:ToWorldSpace(CFrame.new(0,y2Off*self.yMod,-z2Off*self.yMod))
end

return TPath

Any help would be appreciated. The code works fine, but the constant printing of the errors causes immense lag in the game

I’ve tried to reproduce the error with your scripts and I am getting no errors… Do you think you could provide a copy of your place?

TrackMathTesting.rbxl (49.3 KB)

Yeah play testing that place file doesn’t seem to return any errors. Perhaps that error is being fired from another script?

cloud_5630413655.obfscrpt:1: invalid argument #1 to ‘pairs’ (table expected, got nil)

The error isn’t from your script, it’s from a plugin passing nil to pairs at line 1.

Turns out it was a plugin. Thanks

1 Like

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