Need help with finding table

I was making a party system using tables, but I realised I don’t know anything about tables. I did my research and found nothing.
It always results in not being able to find the room.

local rooms = {}

local function Setup(host)
	print(host.Name)
	rooms[host.Name] = {host.Name}
	print(rooms)
end
createEvent.OnServerEvent:Connect(Setup)

local function Start(host)
	print(host.Name)
	if table.find(rooms, host.Name) then
		TeleportPlayers(rooms[host.Name])
		print("Teleporting players...")
	else
		warn("Could not find the requested room.")
	end
end
startEvent.OnServerEvent:Connect(Start)

All events return in a player’s nickname btw.

your tables look like this

{
    ["player"] = {"player"}
}

table.find looks for the value, not the index,
you’d either have to change rooms to not use string indexes

table.insert(rooms,host.Name)
table.find(rooms,host.Name)

or a for loop

local found = false
for i,_ in pairs(rooms) do
	if i == host.Name then
		found = true
		break
	end
end

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