Elimination issue + teleport issue

Hello everyone! I am making a game where each round there is a different obby map and the idea is to eliminate the player with least progress in it.

So, I was using “checkpoints” (they are not really checkpoints) that give players tags with numbers to mark the players’ progress, but someone told me to use an IntValue, and that is what I am using right now…

However, since I started using IntValue, there are 2 problems that I hadn’t seen when using tags. I’ve been testing the game with me and my alt account in the same server.

  • No matter if player A or player B has more progress, the game is always eliminating (changing to Spectators team) the player B. I don’t know why.

  • When player A reaches the end of the obby, and gets teleported to lobby, the player B gets teleported as weel, and vice-versa.

Does anyone know why that is happening? I was really frustrated when that happened because that hadn’t happened when I used tag numbers…And by the way, If i press F9 there are no errors in the server nor in the client.

I will post my scripts in the reply.

1 Like

This 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”)

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

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)

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 stage = char.Stage.Value
	if stage < lowestStage then
		lowestStage = stage
		slowestPlayer = player
	end
end

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

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

Status.Value = slowestPlayer.Name

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

ChosenMap:Destroy()

end

And these are scripts for the “checkpoints”:

(This is for checkpoint 1)

local stageNumber = 1 – Change this to whatever stage number you’re using

script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
if hit.Parent.Stage.Value > stageNumber then
hit.Parent.Stage.Value = stageNumber
end
end
end)

(This is for checkpoint 4):

local stageNumber = 4 – Change this to whatever stage number you’re using

script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
if hit.Parent.Stage.Value > stageNumber then
hit.Parent.Stage.Value = stageNumber
end
end
end)

And here is the teleporter script:

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)

Your code is a bit complex, has too many details and is difficult to follow as a viewer, can you explain each part of the code with comments?

The first issue is that at the very end of your teleport script, you teleport every player if anyone touches the part.

1 Like

Oh and how can i correct that?

script.Parent.Touched:Connect(function(player)
    if Player.Character and Player.Character:FindFirstChild(‘Humanoid’) then
        Player.Character.HumanoidRootPart.CFrame = RandomLobbySpawn.CFrame
    end
end)
--that is the right code I think

oh you need to change all “Player” to “player” in my code

1 Like

Ok I will try it now then I come back to tell what happened.

Ok, now no one was teleported ;-;

It said there is an error in line 6 because Character is not a part of workspace.Laverr54

oh I get the error xD you should replace it with this:

script.Parent.Touched:Connect(function(hit)
   local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr then
       hit.Parent.HumanoidRootPart.CFrame = RandomLobbySpawn.CFrame
-- I pretty sure that if you replace hit.Parent.HumanoidRootPart with just "hit"
--it will work too but idk
    end
end)
1 Like

Oh thank you! Now only who touches the teleporter gets teleported (:

But still player B is always the eliminated one even when he wins… I think there is something wrong with “slowestPlayer” do you know how to correct that?

I think you meant hit.parent.Stage.Value < stageNumber
You also don’t have a default value for Stage.

1 Like

Bruh i just realised its not working yet. I thought it was :frowning:

Try spamming prints in the script like print(lowestStage .. slowestPlayer), print(player .. stage) and testing them in game. Does it still only eliminate player B?

Also why is this a for loop:

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

Now I think it is choosing a random player to eliminate everytime, I think it is choosing the “slowest player” in the beginning so its random, sometimes player A is eliminated now…

And i don’t know why i wrote for _, I was just trying to write it and that’s how i did it, What is the right way to write it?

there is no “right” way to type it.
_ is what you chose to write. _, in that case, means the current loop number in the loop
if you put “i” it will still have the same meaning but just a different way to call it

local module = {"hey", 2, true}

for i, v in pairs(module) do
     print(i)
end
print("finished loop 1")
-- it will do the same things as the other loops below

wait(2)

for _, v in pairs(module) do
     print(_)
end
print("finished loop 2")

wait(2)

for loopNumber, v in pairs(module) do
     print(loopNumber)
end
print("finished loop 3")

hope you get that, if you don’t just tell me what you don’t understand

1 Like

oh…I forgot that _ is a placeHolder. _ is the only thing that is different then the other names and means
that you will not call that in the loop

1 Like

So now i changed that part to:

slowestPlayer.Team = Spectators

And in the 1st round it eliminates the player with least progress, but then in the other rounds, it keeps eliminating the one eliminated in the first round (almost all of the times) I have no idea why…

I’m so frustrated

Try this

for _, player in pairs(Players:GetPlayers()) do
    if player.Team == Spectators then continue end -- don't check the spectators

	local char = player.Character
	if not char then continue end
	
	local stage = char.Stage.Value
	if stage < lowestStage then
		lowestStage = stage
		slowestPlayer = player
	end
end

slowestPlayer.Team = Spectators
slowestPlayer.Character.Stage.Value = math.huge -- change to whatever your default value is