"If" / "if not" to find lowest tag number

The error is likely something I explained in the post, but did not give a proper piece of code for.
You need to insert an intvalue into the player’s character, which you can do like this:

local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
  player.CharacterAdded:Connect(function(char)
    local stageValue = Instance.new("IntValue", char)
    stageValue.Name = "Stage"
  end
end)
1 Like

Oh okay, thanks for letting me know. I will try it later, now I’m testing the other code from deafaultyboii1324

Wait, what do you mean by “location of tag val”? ChosenMap.Part1? Or is it a number?
I don’t understand.

It’s the tag number for the player. If the player has the tag number of 6, that’s what you would put there.

1 Like

But the number depends, it can be any number from 0 to 7 depending on how far the player went

1 Like

So i put this code in the checkpoints or in the main script? Also, it is saying that there is a syntax error in “end)”

I forgot to place a ) at the end of the player.CharacterAdded function.
Change the last 2 lines to this:

  end) -- I forgot the ) here
end)

You should place this in the main script

1 Like

Oh okay, thanks I will try now

So there is still error in the checkpoints line 5

And there is still an error in line 97 of the main script

Captura de Tela (3864)

Captura de Tela (3865)

I don’t know if i put the main script in the wrong order or something and also I have no idea why the checkpoints script is not working in line 5.

Wait, do i need to add an IntValue manually in every checkpoint? I didn’t do that.

The intvalue needs to be inserted into the player’s character. Without having the full script as it is right now, the only guess I could make is that you placed the piece of code I gave you after the while true do loop. If you could give the current script, I can help a bit further though.

1 Like

Sorry if I was making it unclear but, PlayerVal and PlayerNum are where you put the tag value according to the player. So if I had the tag value in the leaderboard I would do something like this,

PlayerVal = v.leaderstats.tag.Value -- the value of the tag
PlayerNum = v.leaderstats.tag.Value -- the value of the tag

v is the player, leaderstats.tag.Value is getting the value. local pn = 6 was put in for testing purposes so I knew that the script actually worked.

1 Like

Yes I put in after the while true do loop, here is the full 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”)

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 slowestPlayer = nil
local lowestStage = math.huge -- This will ensure that the first check will always pass

for _, player in pairs(Players:GetPlayers()) do
	local char = player.Character
	if not char then continue end
	
	local players = game:GetService("Players")
	players.PlayerAdded:Connect(function(player)
		player.CharacterAdded:Connect(function(char)
			local stageValue = Instance.new("IntValue", char)
			stageValue.Name = "Stage"
		end)
	end)
	
	local stage = char.Stage.Value
	if stage < lowestStage then
		lowestStage = stage
		slowestPlayer = player
	end
end

for _, Player in pairs(Players:GetChildren())do
	slowestPlayer.Team = Contestants
end
	
Status.Value = 'The eliminated player is: '

ChosenMap:Destroy()

end

Oh that’s nice so how can i add the tag in the leaderstats? It would be useful to test.

You should put it in before the while true do loop, otherwise lua won’t ever execute those lines of code because it keeps looping in the while true do loop.

1 Like

I didn’t know that :sweat_smile: So i put it before the loop, and also i corrected the part that I had written alone, which was wrong (I wrote the wrong team):

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

Then I tried again, and now there are no errors!
The only problem is that when I reached the end of the obby and was teleported to lobby, my alt account was teleported too /:

This is the script of the “Teleport” part, which is the last one in the obby, which teleports to lobby:

Players = game:GetService(“Players”)
local LobbySpawns = game.Workspace.Lobby:FindFirstChild(‘LobbySpawns’):GetChildren()
local RandomLobbySpawn = LobbySpawns[math.random(1, #LobbySpawns)]

script.Parent.Touched:Connect(function()
for _, Player in pairs(Players:GetChildren())do
if Player.Character and Player.Character:FindFirstChild(‘Humanoid’) then
Player.Character.HumanoidRootPart.CFrame = RandomLobbySpawn.CFrame
end
end
end)