Why this code doesn't work?

Hello, I am a scripter but I’m still learning code

I made a script that reservers a server for some specific players and when the countdown reaches 0, then it teleports the selected players. But, the script doesn’t work

local CountdownServer = game.ReplicatedStorage.Parties.NormalServer.Countdown
local ServerStatus = game.ReplicatedStorage.Parties.NormalServer.Stats

local TS = game:GetService("TeleportService")
local Server = "NormalServer"

function ChangeServer(art)
	if art == "NormalServer" then
		code = TS:ReserveServer(5070728964)
	end
end

while true do
	if game.ReplicatedStorage.Parties.NormalServer.PlayersNumber.Value >= 1 then
		local Countdown = 30
		ServerStatus.Value = "Enable"
		repeat
			Countdown = Countdown - 1
			CountdownServer.Value = Countdown
			wait(1)
		until Countdown == 0
		ServerStatus.Value = "Teleporting"
		ChangeServer(Server)
		for i, player in ipairs(game.Players:GetChildren()) do
			if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
    			if player.InNormalParty.Value == true then
       				TS:TeleportToPrivateServer(5070728964, code, {player})
   				end
			end
		end
	end
end

Pls, tell me what is wrong or tell me a better way to make the code, thanks.

The wrong line is :

for i, player in ipairs(game.Players:GetChildren()) do
            if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
                if player.InNormalParty.Value == true then
                       TS:TeleportToPrivateServer(5070728964, code, {player})
                   end
            end
        end

(Sorry for my english, i am spanish)

1 Like

Remove the brackets {} from player. It’s not a table

1 Like

Thanks, but it still broke, output:
Script timeout: exhausted allowed execution time(I fixed this error lol)

This means that you haven’t added a wait in your while loop and it runs extremely fast, to clear this up, add a wait of () or 1 at least.