#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)
Can you explain a little better?
How about this how do I make it so it will detect all players that are not inside a specific table
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
Yeah so for the if statement would I do if player.Parent = gameplayers do or is it something else?
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?
yeah get the humanoid and set health to 0
** You are now Level 1! **
first parameter is the table, second is the player
table.find(gameplayers, player)
Is this along the right lines? Also an error shows up with the current code displaying attempt to iterate over a Instance value
Could you not use if not table.find
I think you can in Roblox so instead of and if and else
But the for loop would be better to use since it goes through all players inside the table right?
Oh wait
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
ikr
Can you show the output error?
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
Btw "Players" might not be a list
How did you get the players?
Alr currently testing it btw what does _, do in the code I never really understood what it does
Comes up with error
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
can you show what the variable "GamePlayers" is
Ohhh I see
what type of data is stored in there
alright what about "Players" you used in the for loop
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
alright so instead of just "Players" it needs to be "Players:GetPlayers()"
Wait where I would I put Players:getplayers()
Would it be for the variable?
Cheers
Local Player = game.player:Get players()
I think he just meant change the line
local Players = game.GetService("Players")
To
local Players = game.Players:GetPlayers("Players"(
nah he already did it
your way isn't wrong but it won't update
Ohhh I see in the parameters
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
That's smart I get you passes the players instead of a constant
Thx man tysm for helping me!
I'm glad! have fun developing
** You are now Level 2! **
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
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
Oh I see if I had 12 UserIDs how would I write the whole thing?
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
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?
@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
??
When a player activates a proximity prompt, their player gets registered into GamePlayers at direct indexes eg [4]
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
alright i think i understand
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
Thx and can removeunauthorisedplayers() be called anytime?
** You are now Level 9! **
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
Cheers I’ll probs try testing this in the morning since I gotta go sleep
yeah fair enough enjoy
Aight
Btw tysm for helping me with this I really appreciate the help
all good i enjoy helping it helps me learn alot
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?
New table along with the direct index table
well whats your issue
just do table.clear(tablename) to remove them from the table
The issue was I needed the direct index table to have player images appear on and off frequently throughout the game whilst having this one that worked but have all the players kept in there. Also, if a player was to die or leave how would I remove them from my table?
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