Add Players To Table with different variety

  1. **What do you want to achieve?
    so i was making a table with different variety
  2. **What is the issue?
    so basically my table have 2 variety call survivor and hunter , i have 2 button that will let you join to survivor or hunter . the issue is i don’t know how to insert the player when there is two variety in a table . here is a script below .

local shirts = {
survivor1 = ,
survivor2 = ,
survivor3 = ,
survivor4 =,
hunter =
}

1 Like

I use something pretty similar in my game, and I just use table.insert(table, plr).
Isn’t it better to have a list of survivors instead? But if you want to keep it like this you can do

shirts.hunter = Player
1 Like

but i need to connect this to a teleport system , so i only can make 1 table . also i dont want random join . what i need is when a player press survivor button . there will join to the survivor variety in the table

hmmm…let me think

button.Activated:Connect(function()

end)

and there you can player to table

what about hunter ? hunter also need to join with the same server as survivor .

I didn’t quite understand what you are trying to achieve. Can you elaborate please

You just use two scripts for two buttons. I would also add RemoteEvent because tables should be edited on server

so i need a matchmaking system , with 2 different teams . you can join them by either pressing survivor or hunter . the reason i use table is cuz i want to tp them to other server .

You can pass data while teleporting a player though, I did not understand what you are trying to do exactly but what I have said may help. Let me know if you want me to explain how to pass data using teleport service.

i know but what i want is make a match first before going to other server . so its more easy .
its like a mobile legend matchmaking system . 2 different variety in 1 table , when they are prepared then they all get teleported to other server .

What I would do is that I would create a StringValue in each player. Based on what button the player presses the StringValue will change to “Survivor” or “Hunter”. Then in the script I would do something like this:

local Players = game:GetService("Players")

local Hunters = {}
local Survivors = {}

for i,v in pairs(Players:GetChildren()) do
   if v:WaitForChild("Role").Value == "Survivor" then
      table.insert(Survivors,v.Name)
   else
       table.insert(Hunters,v.Name)
   end
end

If this works don’t forget to mark this as a solution :wink:

1 Like

now i know how to insert the player , but can you also teach me how to detect when there is 1 player in hunter table and 4 player in survivor table?

you can do #TableName to find the number of values in a table

1 Like

how do i get the string value from player ? cuz my string value is in leaderstats

Like this

local Players = game:GetService("Players")

local Hunters = {}
local Survivors = {}

for i,v in pairs(Players:GetChildren()) do
   if v:WaitForChild("leaderstats").Role.Value == "Survivor" then
      table.insert(Survivors,v.Name)
   else
       table.insert(Hunters,v.Name)
   end
end
1 Like

thanks for the help ! i hope i can make a good game .

quick question , i don’t have anyone to help me test out the script . so can you tell me if this is working or not?

 local Players = game:GetService("Players")

local Hunters = {}
local Survivors = {}

for i,v in pairs(Players:GetChildren()) do
	if v:WaitForChild("leaderstats").Role.Value == "Survivor" then
		table.insert(Survivors,v.Name)
	else
		table.insert(Hunters,v.Name)
	end
end

repeat wait() until #Hunters == 1
	if #Survivors == 4 then
		print("teleport service here , havent type it out yet lol")
	end