Issues with using data from table to put into textlabel

local CelebrityHeightScanner = workspace:WaitForChild("CelebrityHeightScanner")

local Scanner = CelebrityHeightScanner:WaitForChild("Scanner")

local HeightDisplay = CelebrityHeightScanner:WaitForChild("Base"):WaitForChild("ScannerResults"):WaitForChild("Holder"):WaitForChild("HeightDisplay")

local ResultsDisplay = CelebrityHeightScanner:WaitForChild("Base"):WaitForChild("ScannerResults"):WaitForChild("Holder"):WaitForChild("ResultsDisplay")

local factor = 10^2

local function MetersToFTAndIn(Height)
	
	-- Define the conversion factor for meters to feet
	local metersToFeet = 3.28084

	-- Convert the length to feet
	local lengthInFeet = Height * metersToFeet

	-- Calculate the whole feet part
	local feetPart = math.floor(lengthInFeet)

	-- Calculate the remaining inches part
	local inchesPart = (lengthInFeet - feetPart) * 12

	if inchesPart % 1 ~= 0 then
		
		return feetPart .. "' " .. math.floor(inchesPart * factor + 0.5) / factor .. '"'

	end
	
end

local CelebrityHeightData = {
	[1.47] = { -- 4'10
		"Danny DeVito";
		"Edith Piaf";
		"Madeleine Albright";
	};
	[1.5] = { -- 4'11
		"Judy Garland";
		"Kristin Chenoweth";
		"Estelle Getty";
	};
	[1.52] = { -- 5'0
		"Dolly Parton";
		"Hayden Panettiere";
		"Sabrina Carpenter";
	};
};

local db = false

Scanner.Touched:Connect(function(hit)
	
	if hit.Parent:FindFirstChild("Humanoid") then
		
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		
		if plr and db == false then
			
			db = true
			
			local PlrHeight = math.floor(plr:WaitForChild("Height (m)").Value * factor + 0.5) / factor
			
			local ScanTime = 3
			
			HeightDisplay.Text = MetersToFTAndIn(PlrHeight)
			
			Scanner.Color = Color3.fromRGB(255, 25, 17)
			
			ResultsDisplay.TextColor3 = Color3.fromRGB(184, 184, 184)
			
			ResultsDisplay.Text = "Scanning..."
			
			task.wait(ScanTime)
			
			local SimilarCelebHeights = {}
			
			for Height,Data in pairs(CelebrityHeightData) do
				
				if Height == PlrHeight then
					
					for index = 1,3 do
						
						table.insert(SimilarCelebHeights,Data[index])
						
						task.wait()
						
					end
					
				end
				
			end
			
			table.concat(SimilarCelebHeights, ", ")
			
			ResultsDisplay.TextColor3 = Color3.fromRGB(239, 184, 56)
			
			ResultsDisplay.Text = table.unpack(SimilarCelebHeights)
			
			Scanner.Color = Color3.fromRGB(71, 255, 92)
			
			db = false
			
		end
		
	end
	
end)

--[[

[1.55] = "Thinks They Are Cooler Than 5'0"; -- 5'1
[1.57] = "Kevin Hart"; -- 5'2
[1.60] = "The Height Complainer"; -- 5'3
[1.63] = "Average American Female"; -- 5'4
[1.65] = "1 Foot Shorter Than THE ROCK"; -- 5'5
[1.68] = "Unfortunate Height For Males To Stop Growing"; -- 5'6
[1.70] = "Average Worldwide Male & Netherlands Average Female"; -- 5'7
[1.73] = "Flexes on 5'7"; -- 5'8
[1.75] = "Average American Male & Above Average Female"; -- 5'9
[1.78] = "1 Inch Cooler Than 5'9"; -- 5'10
[1.80] = "Slightly Above Average Male & Not The 6'0 Family"; -- 5'11
[1.83] = "Above Average Male & Netherlands Average Male"; -- 6'0
[1.85] = "Borderline Tall"; -- 6'1
[1.88] = "Pretty Tall"; -- 6'2
[1.91] = "Tall"; -- 6'3
[1.93] = "Human Tower"; -- 6'4
[1.96] = "THE ROCK"; -- 6'5
[1.98] = "Average NBA Player"; -- 6'6
[2.01] = "1 Foot Taller Than An Average Male"; -- 6'7
[2.03] = "Height Of A Door"; -- 6'8
[2.06] = "Weird Height"; -- 6'9
[2.08] = "Makes Ceiling Fans Nervous"; -- 6'10
[2.11] = "1 Inch Less Cooler Than 7'0"; -- 6'11
[2.13] = "Rumeysa Gelgi (Tallest Living Female)"; -- 7'0
[2.16] = "Shaq (the former basketball guy)"; -- 7'1
[2.43] = "Human Monument"; -- 8'0
[2.51] = "Sultan Kösen (Tallest Living Person)"; -- 8'3
[2.71] = "Robert Wadlow (Tallest Person Who Lived)"; -- 8'11

--]]

The results display will only get one person’s name for some reason.

1 Like

try this

			ResultsDisplay.Text = table.concat(SimilarCelebHeights, ", ")
			
			ResultsDisplay.TextColor3 = Color3.fromRGB(239, 184, 56)
			
			Scanner.Color = Color3.fromRGB(71, 255, 92)
1 Like

Worked! Can you just explain why my code is incorrect and why i couldnt have done this as well?

for Height,Data in pairs(CelebrityHeightData) do
				
				if Height == PlrHeight then
					
					table.insert(SimilarCelebHeights,Data)
					
				end
				
			end

To display all the names in SimilarCelebHeights as a single string separated by commas, you should use table.concat instead. Replace the line that sets the ResultsDisplay.Text

1 Like

try with ResultsDisplay.Text = table.concat(SimilarCelebHeights, ", ")

1 Like

Can you please explain why my code was incorrect?

it was from attempting to set the ResultsDisplay.Text property. Instead of concatenating all the celebrity names stored in the SimilarCelebHeights table, you wrong used table.unpack(SimilarCelebHeights) , which only displayed the first name and ignored the others. so to correctly display all the names separated by commas, the code should have table.concat(SimilarCelebHeights, ", ") , ensuring that all the celebrity names were properly combined into a single string, resolving the issue.

but why wouldnt i need to use table.unpack?

table.unpack is used to unpack the elements of a table into a list of values, so in your case, you wanted to display all the names of celebrities in the SimilarCelebHeights table as a single string separated by commas.

you should use table.concat to concatenate the names with (, ), as it’s the appropriate function for joining table elements into a string.

1 Like

so unpack puts the elements into a list such as 1,2,3

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