#teamlabelX returns nil

{
[1] = 155,
[2] = 309,
[3] = 462
}

Why not just send a screenshot? (Winkey + Shift + S) but okay

did you print just before you did #teamlabelx

No.

	table.insert(teamlabelX, #teamlabelX + 1, x)
	print(teamlabelX)

Also you dont need to do

table.insert(teamlabelX, #teamlabelX + 1, x)

you can just do

table.insert(teamlabelX, x)

Well is there anyway it can return something?

table.insert doesnt return the updated table

you would have to get the table after inserting

I know that. The code does not do that.

can you send a place file or a place file just with the leaderboard and the code

Leaderboard.rbxm (11.9 KB)

Well you are inserting x into the table and trying to get teamName from the table, which doesn’t exist so it returns nil.
If you are trying to create a dictionary, you would do this.

teamlabelX[teamName] = x
print(x, teamlabelX[teamName]) --should return the same

I did that before this post and it just returns 0.

also why are you doing x += 155 - #teamlabelx

155+(80/(2-1)). This is the code for the spacing.

It shouldn’t return 0 unless you put teamlabelX[teamName] = x before increasing the x value.

	x += 155 - #teamlabelX
	local LSLabel = script:WaitForChild("LSLabel"):Clone()
	--  LSLabel.Position = UDim2.new(0,0,0.036,0)
	LSLabel.Text = teamName
	LSLabel.Parent = leaderboard:WaitForChild("labels")
	teamlabelX[teamName] = x
	print(teamlabelX)
	print(x, teamlabelX[teamName])
	
	leaderboard.Position -= UDim2.new(0,100,0,0)
	leaderboard.Size += UDim2.new(0,100,0,0)

And what does it print?
If x is 155 it should print:

{
    [teamName] = 155
}
155 155

Yes it prints that. Maybe it was my coding?

#teamlabelX should return 3. ndfgnhgdfjjgjibghijtgtyjijtthgffddxsfsdhjaswjurwydersydfshyfhfhfhdf

Why should it return 3? If it’s the length, you can’t get the length of a dictionary unless you iterate through it.

--example using a function
local function dictionaryLen(Dictionary)
	local count = 0
	for _, _ in pairs(Dictionary) do
		count += 1
	end
	return count
end

local testDictionary = {
	["test"] = 123;
	["test2"] = 456;
	["test3"] = 789;
}

print(#testDictionary, dictionaryLen(testDictionary)) --returns 0 3