So I have this piece of code that finds the player with the most of a data but whenever I try and export the winning player to a String Value with their username it comes back with a errors as nil and doesn’t export it.
Here is the code (Someone on Devfourm helped right it):
wait(5)
local function FindTopPlayers()
local One = -1
local Two = -1
local Three = -1
local Plr1, Plr2, Plr3
for _, plr in ipairs(game.Players:GetPlayers()) do
if One < plr.playtime.PlaytimeValue.Value then
Plr3 = Plr2
Three = Two
Plr2 = Plr1
Two = One
Plr1 = plr
One = plr.playtime.PlaytimeValue.Value
elseif Two < plr.playtime.PlaytimeValue.Value then
Plr3 = Plr2
Three = Two
Plr2 = plr
Two = plr.playtime.PlaytimeValue.Value
elseif Three < plr.playtime.PlaytimeValue.Value then
Plr3 = plr
Three = plr.playtime.PlaytimeValue.Value
end
end
game.Players:FindFirstChild(Plr1).Team = game.Teams.Mayor
end
FindTopPlayers()
I used print(plr1) and it came back correct, but when I try to get that name out into a String Value or find the player in game.Players it comes back with this error:
ServerScriptService.MayorTesting:31: attempt to index nil with 'Team' - Server - MayorTesting:31
16:27:15.193 Stack Begin - Studio
16:27:15.193 Script 'ServerScriptService.MayorTesting', Line 31 - function FindTopPlayers - Studio - MayorTesting:31
16:27:15.194 Script 'ServerScriptService.MayorTesting', Line 34 - Studio - MayorTesting:34
16:27:15.194 Stack End - Studio