Im trying to sort player join order in a local script but I cant figure it out and I thought about this bbut I dont know how to make this can someone help me?
Hi, the table will already be sorted based on when people join. table.insert will add the player's name at the end of the table. The if statement you have inside of the playeradded function will not work as the player joining will always be the player you need to add to the array.
gtg so i didnt get to test this: Serverscript:
01 | local sortedPlayers = { } |
02 |
03 | local Text = "" |
04 | function getIndex(playerName) |
05 | for i = 1 , #sortedPlayers do |
06 | if (sortedPlayers [ i ] = playerName) then |
07 | return i |
08 | end |
09 | end |
10 | end |
11 |
12 | game.Players.PlayerAdded:Connect( function (plr) |
13 | --player who just entered will never not be player |
14 | table.insert(sortedPlayers, plr.Name) |
15 | end ) |
Script:
01 | --By enes223 |
02 | local Remote = game:GetService( "ReplicatedStorage" ):WaitForChild( "UserSender" ) |
03 |
04 | local Players = { } |
05 |
06 | local Text = "" |
07 |
08 | game.Players.PlayerAdded:Connect( function (plr) |
09 | if not Players [ plr.Name ] then |
10 | table.insert(Players,plr.Name) |
11 | for i,v in pairs (Players) do |
12 | Text = Text..v.. "," |
13 | Remote:FireClient(plr,Text) |
14 | Remote:FireAllClients(Text) |
15 | end |
Local Script:
01 | --By enes223 |
02 | local Sorter = game:GetService( "ReplicatedStorage" ):WaitForChild( "Sorter" ) |
03 | local Remote = game:GetService( "ReplicatedStorage" ):WaitForChild( "UserSender" ) |
04 |
05 | local U 1 ,U 2 ,U 3 ,U 4 ,U 5 = script.Parent.User 1 ,script.Parent.User 2 ,script.Parent.User 3 ,script.Parent.User 4 ,script.Parent.User 5 |
06 | local I 1 ,I 2 ,I 3 ,I 4 ,I 5 = U 1. Index,U 2. Index,U 3. Index,U 4. Index,U 5. Index |
07 |
08 | local SortedTable = { } |
09 | local Indexes = { I 1 ,I 2 ,I 3 ,I 4 ,I 5 } |
10 |
11 | function Seperate(Text,Seperator) |
12 | local SubNumber = 1 |
13 | local Line = Text:sub( 1 ,SubNumber) |
14 | repeat |
15 | Line = Text:sub( 1 ,SubNumber) |