Ad
Log in to vote
0

How to remove a string from GetChildren() ?

Asked by 1 year ago
game:GetService('Teams'):GetChildren()

I want to remove a team from this table(I think this is a table) But I don't know how to do so.

Attempt 1 (Using table.remove())

Code :

local team = game:GetService("Teams"):GetChildren()
table.remove(team , "Lobby")

Output :

ServerScriptService.Script:2: bad argument #2 to 'remove' (number expected, got string)

Attempt 2 (Finding the position and then removing it with table.remove())

Code :

local team = game:GetService("Teams"):GetChildren()
print(team)

Output :

table: 0xe3a8b27dd6e99e38

Help is really appreciated!!!

0
table.remove() take two argument. First one is the table, second one is the position of the key. But :GetChildren() is alway return a random order table, so it hard to know the position of "Lobby". Block_manvn 394 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago

Sadly, Roblox doens't supply a way to get the index of an item from an array. But you can use this workaround:

local teams = game:GetService("Teams"):GetChildren()
local team = teams.Lobby

for key,value in pairs (teams) do
    if team then
        table.remove(teams,team)
    end
end

Even then, why would you want to remove the team?

0
you can do `array[index]` to get an item at a specific index User#23252 26 — 1y
Ad

Answer this question