Help please - Refer to player

Guys I need help quick

How can i refer to the player that has the lowest tag number?

I wish I could help, but first I’d need to know what a ‘tag number’ is.

Ok I will paste other text i made to explain it better

I am making a game where each round there is a different obby map, and players have to complete it in 5 minutes, for example, then a new map appears.

I want to eliminate the player with least progress in the round, just 1 player each round.

I’ve been trying to put some “checkpoints” (its not really a checkpoint) that give the players a tag with a number, to keep their progress. If a player falls from the “checkpoint 5” they will go back to the beginning, and when steps on the “checkpoint 1” their tag number will still be 5 because i put this code in the checkpoints:

(This is for checkpoint 4)

local cs = game:GetService(“CollectionService”)

script.Parent.Touched:Connect(function(part)
if part.Parent:FindFirstChild(“Humanoid”) and not part.Parent >4 then
cs:AddTag(part.Parent, “4”)
end
end)

So this seems to be going well, but I need help with my main script: how to refer to the player with the lowest tag number?

The elimination would be go from Contestants team to Spectators team.

You can create a function like this:

local players = game.Teams.insertPlayingTeamHere

local function getLowestTag()
    local tab,array = {},{}
    for _,player in pairs(players:GetPlayers()) do
        tab[player.Name] = player.Tag.Value
    end
    for key,value in pairs(tab) do
	    table.insert({key = key, value = value})
    end
    table.sort(array, function(a, b)
	    return a.value > b.value
    end)
    return players:GetPlayers()[array[#array].key]
end

Obviously you will need to make a few tweaks here and there, but you should get the basic idea.

1 Like

It should work now, but if it doesn’t, feel free to explain your issue :slight_smile:

Omg thanks I will try! I was getting kinda frustrated because everyone kept saying the same things I had already done

I actually just made one more edit. Tell me how it works

1 Like

Okay, I will try to test it XD

So this function will make the game detect the player with the lowest tag number, right? If so, then I still need to know how to say like

PlayerWithLowestTagNumber.Team = Spectators

(I know that’s not the right way to script it)

And also I would need to make everyone except for the PlayerWithLowestTagNumber go to Completed team after the round

Do you know how to do a variable for the PlayerWithLowestTagNumber?

local PlayerWithLowestTagNumber = ???

If you want i can send my main script if that is relevant

Dude, this is incredibly relevant. In fact, not meaning to offend you, but you should have included the part of your script in the original post that contained the method you use to sort the players with “tag numbers.”

1 Like

Like many of the built-in functions, the script I provided you returns the player with the lowest tag number. Try this:

local plrWithLowestTag = getLowestTag()
1 Like

Ok, here is my main script:

ServerStorage = game:GetService(“ServerStorage”)
ReplicatedStorage = game:GetService(“ReplicatedStorage”)
Players = game:GetService(“Players”)
local Team = game:GetService(“Teams”)
local Contestants = game.Teams.Contestants
local Spectators = game.Teams.Spectators
local Completed = game.Teams.Completed
local cs = game:GetService(“CollectionService”)
local gamers = game.Teams.Contestants

Maps = ServerStorage:WaitForChild(‘Maps’):GetChildren()
Status = ReplicatedStorage:WaitForChild(‘Status’)

while true do

--Intermission

local Countdown = 10 -- ten second intermission, make this as long as you want

repeat wait(1)
	Countdown = Countdown - 1

	Status.Value = 'Intermission : '..Countdown
until Countdown <= 0

--Choose the map.

Status.Value = 'Choosing Map...'

local ChosenMap = Maps[math.random(1, #Maps)]:Clone()
local Spawns = ChosenMap:FindFirstChild('Spawns'):GetChildren()
local RandomSpawn = Spawns[math.random(1, #Spawns)]
local LobbySpawns = game.Workspace.Lobby:FindFirstChild('LobbySpawns'):GetChildren()
local RandomLobbySpawn = LobbySpawns[math.random(1, #LobbySpawns)]

wait(5) -- little pause, make this as long as you want

ChosenMap.Parent = workspace
Status.Value =  'Next Map Is: '

wait(2) -- little pause, make this as long as you want

Status.Value = ChosenMap.Name

wait(2) -- little pause, make this as long as you want

--teleport the players

for _, Player in pairs(Players:GetChildren())do
	if Player.Character and Player.Character:FindFirstChild('Humanoid') then
		Player.Character.HumanoidRootPart.CFrame = RandomSpawn.CFrame
	end
end

for _, Player in pairs(Players:GetChildren())do
	Player.Team = Contestants
end

-- Reassign countdown based on chosen map's Duration value
Countdown = ChosenMap:FindFirstChild("Duration").Value

repeat wait(1)
	Countdown = Countdown - 1
	
	local minutes = math.floor(Countdown / 60)
	local seconds = math.floor(Countdown % 60)

	Status.Value = string.format("Time left : %.2d:%.2d", minutes, seconds)
until Countdown <= 0

--Teleport back to lobby

for _, Player in pairs(Players:GetChildren())do
	if Player.Character and Player.Character:FindFirstChild('Humanoid') and Player.Team == Contestants then
		Player.Character.HumanoidRootPart.CFrame = RandomLobbySpawn.CFrame
	end
end

for _, Player in pairs(Players:GetChildren())do
	Player.Team = Completed
end

local function getLowestTag()
	local tab,array = {},{}
	for _,Player in pairs(gamers:GetPlayers()) do
		tab[Player.Name] = Player.Tag.Value
	end
	for key,value in pairs(tab) do
		table.insert({key = key, value = value})
	end
	table.sort(array, function(a, b)
		return a.value > b.value
	end)
	return gamers:GetPlayers()[array[#array].key]
end

local plrWithLowestTag = getLowestTag()

for _, Player in pairs(Players:GetChildren())do
	plrWithLowestTag.Team = Spectators
end

	for _, char in pairs(cs:GetTagged("1", "2", "3", "4", "5", "6", "7")) do -- This removes all tags, for new map
	cs:RemoveTag(char, "1", "2", "3", "4", "5", "6", "7")
end

ChosenMap:Destroy()

end

Thank you XD I will try to use it to see how it works.

I don’t know if i put in the wrong line or something, but now the Chosen Map isn’t destroyed.