How to get a certain value

Hi! Im trying to get the first value in my table through my for loop.

Code:

--vars

local passes = {
	["Levitation"] = 984965343,
	["Baker"] = 986171176,
	["Magician"] = 986212622,
	["Freya"] = 985669421,
	["Test"] = 1245
}

local mps = game:GetService("MarketplaceService")

local LastPos = UDim2.new(0.05, 0,0.025, 0)
local ChangePos = UDim2.new(0, 0, 0.15,0)


--code 
local function CreateButton(parent, Name, txt)
	local Button = Instance.new("TextButton")
	Button.Parent = parent
	Button.Name = Name
	Button.Text = txt
	local size = UDim2.new(0.875, 0,0.1, 0)
	Button.TextSize = 14
	Button.Font = Enum.Font.SourceSansBold
	Button.BackgroundColor3 = Color3.new(0, 0, 0)
	Button.TextColor = Color3.new(1, 1, 1)
end

game.Players.PlayerAdded:Connect(function(plr)
	local plrUI = plr.PlayerGui
	local UID = plr.UserId
	local items = plrUI:WaitForChild("PowerMoves"):WaitForChild("Scroller"):WaitForChild("Items")
	for _, ID in pairs(passes) do
		local PlrOwnsGamepass = mps:UserOwnsGamePassAsync(UID, ID)
		if PlrOwnsGamepass == true then
			CreateButton(items, --I NEED TO GET THE FIRST VALUE, blah blah)
			
		else
			print("Player does not own gamepass.")
		end
	end
	
	
end)

What Im trying to accomplish is that in my table, the IDS are followed by names of the game passes, I need to get that name to use it in my function. Im trying to get these
Screenshot 2024-12-04 at 7.20.18 PM
Thanks!

For loops automatically grab indexs of tables for you when setting them up you just need to change _ to something like index or i and then you can use it just like a normal variable.

for PassName, ID in pairs(passes) do
		local PlrOwnsGamepass = mps:UserOwnsGamePassAsync(UID, ID)
		if PlrOwnsGamepass == true then
			CreateButton(items, PassName, "?")
			
		else
			print("Player does not own gamepass.")
		end
end

You’re a lifesaver! Thank you so much.

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