#Okay Very Simple Request: so I have a set of players within a table, how do I make it so that all

1 messages · Page 1 of 1 (latest)

pulsar flicker
#

The players outside of the table get killed. Bonus request: uhhh how do I get all the players within a table to teleport to a set position but only if they’ve like not made it there yet

prisma lance
pulsar flicker
prisma lance
#

You can loop through all players in the game, and then individually check if they're inside the table. Something like this:

local Players = game.Players:GetPlayers()
local plrTable = {} --add your players


for i, player in Players do
       if table.find(plrTable, player) then
                      -- do what you want if player is in table
              else
                      -- do what you want if player is NOT in table
               end
end

#

formatted weirdly cause on mobile

#

but you get the idea right

pulsar flicker
pulsar flicker
# prisma lance why player.Parent?

Sorry got confused so what would I put within if table.find(gameplayers) and with else, would I need to get the character and humanoid so I can kill the player?

prisma lance
#

yeah get the humanoid and set health to 0

slate glacierBOT
#

studio** You are now Level 1! **studio

prisma lance
#

table.find(gameplayers, player)

pulsar flicker
#

Is this along the right lines? Also an error shows up with the current code displaying attempt to iterate over a Instance value

eager terrace
#

Could you not use if not table.find

#

I think you can in Roblox so instead of and if and else

pulsar flicker
#

Oh wait

eager terrace
#

For loop yes and it will iterate through your list

#

1 sec

#
local Players = game.Players:GetPlayers()
local plrTable = {} -- your table of specific players

for _, player in ipairs(Players) do
    if not table.find(plrTable, player) then
       -- set their humanoid.health = 0
    end
end
#

So hard on mobile

prisma lance
prisma lance
eager terrace
#

I'm using ipairs since it can go over indexes

So imagine your player list
1 Gabe
2 Lucy
3 Devon

1 2 3 are index's which is auto loops through

eager terrace
pulsar flicker
#

Comes up with error

eager terrace
#

So its a placeholder imagine a list like this

{
[1] Lucy
[2] Jake
[3] Garry
}

_ just means the indexes 1 2 3
You use ipairs to go through a list from 1 to nil

#

Index, player

#

1, Lucy
2, Jake
3, Garry

prisma lance
prisma lance
#

what type of data is stored in there

prisma lance
pulsar flicker
#

Also all the code that happens that eventually causes the table.find occurs because of an if statement of a gui I made that only me (the owner) had it enabled for

prisma lance
#

alright so instead of just "Players" it needs to be "Players:GetPlayers()"

pulsar flicker
#

Would it be for the variable?

prisma lance
#

there

pulsar flicker
eager terrace
#

Local Player = game.player:Get players()

pulsar flicker
eager terrace
#

I think he just meant change the line

local Players = game.GetService("Players")

To

local Players = game.Players:GetPlayers("Players"(

pulsar flicker
#

MIGHT BE WORKING NO WAY

#

One quick sec

prisma lance
#

your way isn't wrong but it won't update

eager terrace
#

Ohhh I see in the parameters

prisma lance
#

ykwim? if you call :GetPlayers() at the start and some new players join or leave, the variable will stay the same

#

that's why you need to call :GetPlayers() every new time

eager terrace
#

That's smart I get you passes the players instead of a constant

pulsar flicker
#

IT WORKS

#

YO TYSM

eager terrace
#

Nice bro

#

Good luck on the game

pulsar flicker
prisma lance
slate glacierBOT
#

studio** You are now Level 2! **studio

pulsar flicker
# prisma lance I'm glad! have fun developing

Yo so uhhhh I have it so when each player chooses a player number, they get registered into a specific spot in the table like table.insert(GamePlayers, 5, player) print(GamePlayers[5]) is it possible for the code to work with this since it kills me and states I’m not in he table when I have a spot in the table higher than 1

eager terrace
#

You could set it up like this, Store the players userID into your GamePlayers list
Then loop through players and if they arent in the list they get killed

#
for _, player in ipairs(game.Players:GetPlayers()) do
    if not GamePlayers[player.UserId] then
        --kill player
    end
end
#

you can still keep your idea of player's having a self assigned number but just not use that to loop through the list

pulsar flicker
eager terrace
#
local Players = game:GetService("Players")
local GamePlayers = {}

-- store all the current players userIDs
for _, player in ipairs(Players:GetPlayers()) do
    GamePlayers[player.UserId] = true
end

-- loop through playerID checking if they are in the table
for _, player in ipairs(Players:GetPlayers()) do
    if not GamePlayers[player.UserId] then
        -- kill
    end
end
table.clear(GamePlayers) -- clears the table incase players leave or join
#

store them
then check against it

#

just to help you visualise let me show you whats its doing again

#
GamePlayers = {
   -- userid   true
    [123456] = true, -- is allowed
    [7891011] = true -- is allowed
}
#

the for loop is creating that for you

pulsar flicker
#

Got a problem where even if I don’t have my userid registered into the table, it doesn’t kill me

#

@eager terrace I’ve got functions in the script where it puts a players userid into the script, will I need to change it so it will just sort through that?

eager terrace
#

@pulsar flicker how you are adding players to the list

#

I'm imaging they get to the end of the obby

You maybe then use a touch events in the final platform

#

??

pulsar flicker
#

The code before worked fine but if there were missing indexes eg at 1 and a player wasn’t in the table that player would be stated to not be in the table and die

eager terrace
#

ive tested it and this works

#

the delay gives the player 10 seconds

#

so when the prompt is triggered it fires the onPromptTriggered function and passes the player who did it

then it just assigns them to the GamePlayers list with their userID and a boolean value meaning true

#

then gives them 10 seconds before it clears all players not in the list

pulsar flicker
slate glacierBOT
#

studio** You are now Level 9! **studio

eager terrace
#

yes absolutly, its not passing anything so it should make it easy

#

just keep in mind its using a list that supposedly is full of userIDs so aslong as it has that its good

pulsar flicker
eager terrace
#

yeah fair enough enjoy

pulsar flicker
eager terrace
pulsar flicker
#

Back so I think my best way to fix this is to make a new table without the direct indexes. Also for my new table if a player leaves the game will they not leave the table? So will I need something to remove them from the table if they leave?

pulsar flicker
eager terrace
#

just do table.clear(tablename) to remove them from the table

pulsar flicker
eager terrace
#

so what i think im understanding is :

you want to be able to display the players still remaining using their player profile picture,

for _, player in ipairs(Players:GetPlayers()) do
        if player.UserId == userId then
            return player
        end
    end

if you use a for loop to loop through your players and check if their ID is in the table which holds userIDs you can figure out which players are still alive

#

then display their pfp

#

so with dying or leaving

#
Players.PlayerRemoving:Connect(function(player)
    print("left")
    
end)
#

PlayerRemoving listens for if a player leaves

#

you can then search for the playersid find it in the table and remove it specificially

#
humanoid.Died:Connect(function()
            print("died")
end)
#

this is how you can tell if a player dies