for player, data in pairs(FFAPlayers) do
print(player, data)
local PlayerFrame = Round.FFA:FindFirstChild(player.Name)
Yet player.Name don’t work? When I do
print(typeof(player))
it prints string though!?
Is the output supposed to tell me player is an Instance, even though type is string??
Note, player SHOULD be an Instance. ‘Creator’ is an object value
local function SortTable()
local SortedTable = PlayerStats
local PlayerRank = 1
-- Sort the PlayerStats into order
table.sort(SortedTable, function(a, b)
return a.Tags > b.Tags
end)
for player, v in pairs(SortedTable) do
v.Rank = PlayerRank
PlayerRank += 1
end
return SortedTable
end
PlayerStats[Creator.Value] = {
Rank = 1,
Tags = 1
}
local Sorted = SortTable()
FFAStats:FireAllClients(Sorted)
local function UpdateFFA(scoreData)
FFAPlayers = scoreData
for player, data in pairs(FFAPlayers) do
print(player, data) -- Instance Player2 {...}
print(typeof(player)) -- strng
end
end
and scoreData is mentioned in the OP, FFAStats:FireAllClients(Sorted)
That tells me that the index is a string as it’s wrapped in quotes. Are you ever calling tostring on the player? I find it weird how it’s outputting Instance though. Is there a hyperlink when you hover over the player in the output and it selects the player in the explorer?
I’m thinking you should do one of two things:
1- create a function that returns a player if their name is a string
2- call tostring on the player index
It’s kind of a clunky workaround but I haven’t ever seen anything like this.
I never do tostring. It might have to do with the table.sort tho??
local function SortTable()
local SortedTable = PlayerStats
local PlayerRank = 1
-- Sort the PlayerStats into order
table.sort(SortedTable, function(a, b)
return a.Tags > b.Tags
end)
for player, v in pairs(SortedTable) do
v.Rank = PlayerRank
PlayerRank += 1
end
return SortedTable
end
Yeah, I wouldn’t rely on tostring either. it’s really weird. Table functions are only intended to work with tables though, not dictionaries so maybe that’s why?
I’m not sure either. Genuinely at a loss here haha. Have you tried making your own sort func?
Upon doing further testing, it can’t be the sort function, as both cases return instance
for i, v in pairs(PlayerStats) do
print(i, v)
print("TYPE", typeof(i))
end
print("-----------------------------------------------------")
local Sorted = SortTable()
for i, v in pairs(Sorted) do
print(i, v)
print("TYPE", typeof(i))
end
11:31:40.530 Player2 {…} - Server - FFA:64
11:31:40.530 TYPE Instance - Server - FFA:65
11:31:40.531 ----------------------------------------------------- - Server - FFA:68
11:31:40.531 Player2 {…} - Server - FFA:73
11:31:40.531 TYPE Instance - Server - FFA:74
The issue has to do with using the Player instance as an index, and then sorting it likely. To store as an index the instance is likely serialized, and then sorting doesn’t respect that or something. Is there any reason you can’t just include the Player in the data, like:
local someData = {
Tags = ...,
Player = thePlayer,
}
I always try to use numerical indexes when possible, as it reduces order issues and is faster.
How can I check if a player already has values in the table easily??
if then -- Player already exists, update
else -- Player hasn't gotten a tag yet, add them to the table
local Score = {
Player = Creator.Value,
Tags = 1,
Rank = 1
}
table.insert(PlayerStats, Score)
end
Create another table which references by player, but is not sorted
You used a loop before, so I’ll show the second one.
local scoresByPlayer = {}
--In some function
local plr = Creator.Value
local found = scoresByPlayer[plr]
if found then -- Player already exists, update
--Do stuff with found data for plr
else -- Player hasn't gotten a tag yet, add them to the table
local Score = {
Player = plr,
Tags = 1,
Rank = 1
}
scoresByPlayer[plr] = Score --Since this stores a reference, this will work. Just remember to remove this as well when you remove from the PlayerStats table.
table.insert(PlayerStats, Score)
end