#teamlabelX returns nil

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

  1. What do you want to achieve? Create a leaderstat working leaderboard.

  2. What is the issue? #teamlabelX returns nil.
    issue

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? Looked for solutions in the devforum.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

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

If you need more information just ask me for it.

1 Like

Is this a custom leaderboard? ASGHDHWFAGHSDFASG

Yes. esuih geh yuisfuyirsweui89rfu8erfsduiyerf

Wait. Let me try and make my own custom leaderboard. You can edit it as much as you want. If you don’t want me to do that, just tell me. :slight_smile:

I don’t really know what you’re trying to do in this part of your script, so I’ll make my own.

-- July 23 2022
--By @IAmBanFor

local leaderboard = script.Parent:WaitForChild("leaderboard")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local ChatColor = require(script:WaitForChild("ChatColor"))

local y = 20
local x = 0
local teamlabelX = {} 
leaderboard.Size += UDim2.new(0,0,0,15)

local function getPlrMatching()
	if #Players:GetChildren() < #leaderboard:GetChildren() - 1 then
		local players = {}
		for i,v in pairs(leaderboard:GetChildren()) do
			players[i] = v
		end

		for i,v in pairs(players) do
			if players[i-1] then
				if players[i-1].Text == v.Text then
					players[i-1]:Destroy()
					v.Position -= UDim2.new(0,0,0,20)
					leaderboard.Size -= UDim2.new(0,0,0,20)
				else
					for _,a in pairs(players) do
						if a.Text == v.Text then
							a:Destroy()
							v.Position -= UDim2.new(0,0,0,20)
							leaderboard.Size -= UDim2.new(0,0,0,20)
						end
					end
				end
			else
				for _,a in pairs(players) do
					if a.Text == v.Text then
						a:Destroy()
						v.Position -= UDim2.new(0,0,0,20)
						leaderboard.Size -= UDim2.new(0,0,0,20)
					end
				end
			end
		end
	end
end

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

local function AddLScore(playerName, teamName, score)
	if leaderboard:FindFirstChild(playerName) then
		local ScoreLabel = script:WaitForChild("ScoreLabel"):Clone()
		ScoreLabel.Position = UDim2.new(0,teamlabelX[teamName],0,leaderboard:FindFirstChild(playerName).Position.Y.Offset + 5)
		ScoreLabel.Text = score
		ScoreLabel.Parent = leaderboard
	else
		print("Can't be found because does not exist")
	end
end

local function OnPlayerAdded(playerName)
	local playerLabel = script:WaitForChild("PlayerLabel"):Clone()
	playerLabel.Name = playerName
	playerLabel.Text = playerName
	playerLabel.TextColor3 = ChatColor(playerName)
	playerLabel.Parent = leaderboard
	
	playerLabel.Position += UDim2.new(0,0,0,y)
	leaderboard.Size += UDim2.new(0,0,0,20)
	
	y += 20
end


local function OnPlayedLeft(playerName)
	if leaderboard:FindFirstChild(playerName) then
		leaderboard:FindFirstChild(playerName):Destroy()
	else
		print("Can't be deleted because does not exist")
	end
end



ReplicatedStorage:WaitForChild("OnPlayerAdded").OnClientEvent:Connect(OnPlayerAdded)
ReplicatedStorage:WaitForChild("AddLSName").OnClientEvent:Connect(AddLSName)
ReplicatedStorage:WaitForChild("AddLScore").OnClientEvent:Connect(AddLScore)
1 Like

Are you trying to position the player’s name/label? If you are, you could just slap in a UIGridLayout into the frame.

Yes but it would ruin the Gui but a folder would work.

1 Like

Also I need the table in order to position the Score.

1 Like

issue 2

1 Like

I don’t know what you want it to look like. Can you draw it out in MS paint or smthing? :grimacing:
sorry.

1 Like

Hope this is good for you! If it doesn’t fit your style, you can always change it!

Leaderboard.rbxl (38.5 KB) (Not scripted)

If you click on a player, it will show their stats.

1 Like

Oh, you want an old roblox style?

Yes I do. The script is called 08ClientHandler.

:grimacing: Sorry, I don’t really know how to do that otherwise. I’ll try.

Did you read the title? I want #teamlabelX to return a number.

can you send a screenshot of the table

local teamlabelX = {} 

Add to the table using table.insert.

I mean like send a screenshot of the table printed in the output

E.G:
image