Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How To Find Table Value's Position?

Asked by
enes223 327 Moderation Voter
5 years ago

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?

0
This an xy problem. You actually want to sort player join order but you instead ask how to find a table's value position programmerHere 371 — 5y

2 answers

Log in to vote
1
Answered by
royaltoe 5144 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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:

01local sortedPlayers = {}
02 
03local Text = ""
04function getIndex(playerName)
05    for i = 1, #sortedPlayers do
06        if(sortedPlayers[i] = playerName)then
07            return i
08        end
09    end
10end
11 
12game.Players.PlayerAdded:Connect(function(plr)
13    --player who just entered will never not be player
14    table.insert(sortedPlayers, plr.Name)
15end)
View all 30 lines...
0
Ill try when I get the laptop :D enes223 327 — 5y
0
Ok tell me how it goes royaltoe 5144 — 5y
0
Thanks so much! enes223 327 — 5y
0
pls mark it as solved and upvote since it worked royaltoe 5144 — 5y
Ad
Log in to vote
0
Answered by
enes223 327 Moderation Voter
5 years ago

Script:

01--By enes223
02local Remote = game:GetService("ReplicatedStorage"):WaitForChild("UserSender")
03 
04local Players = {}
05 
06local Text = ""
07 
08game.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
View all 27 lines...

Local Script:

01--By enes223
02local Sorter = game:GetService("ReplicatedStorage"):WaitForChild("Sorter")
03local Remote = game:GetService("ReplicatedStorage"):WaitForChild("UserSender")
04 
05local U1,U2,U3,U4,U5 = script.Parent.User1,script.Parent.User2,script.Parent.User3,script.Parent.User4,script.Parent.User5
06local I1,I2,I3,I4,I5 = U1.Index,U2.Index,U3.Index,U4.Index,U5.Index
07 
08local SortedTable = {}
09local Indexes = {I1,I2,I3,I4,I5}
10 
11function Seperate(Text,Seperator)
12    local SubNumber = 1
13    local Line = Text:sub(1,SubNumber)
14    repeat
15        Line = Text:sub(1,SubNumber)
View all 46 lines...

Answer this question