Ok so essentially I have 2 questions.

Question #1:

So after this script is run I teleported my players into the map I want and now I want to change their characters parent so that when they are done other players can join that map. This is the important part of the code:

if game.ServerStorage.Map.Time.Value == 0 then
		print "Teleported"
		
		local players = game.Workspace.PlayersMap:GetChildren()
		
		for i = 1, #players do
			rootpart = players[i].HumanoidRootPart
			wait (0.5)
			rootpart.CFrame = CFrame.new(-21.5, 1.5, -76.75)
			
			rootpart.CFrame = CFrame.new(-21.5, 1.5, -76.75)
			
			rootpart.CFrame = CFrame.new(-21.5, 1.5, -76.75)
			
			rootpart.CFrame = CFrame.new(-21.5, 1.5, -76.75)
			
				wait (1)
				
				playerparent = players[i].Parent
				
			
			
				playerparent = game.Workspace
				
				print "Parent Changed"
			
			game.ServerStorage.Map.Players.Value = 0
			
			
			
			game.ServerStorage.Map.Closed.Value = true
			
			
		end
		
	end

So it prints Parent Changed but when I switch from client mode to server the parent is still the same and I get no error why is that so? Everything else in the script like setting the players value and closed value works fine.

Question #2

Ok so this is the more important one im trying to make it that a person can join the thing for a map but then they can leave. I have the leaving part when a player presses the leave button in their gui it fires a remote event that changes the parent of the player from the map folder to workspace so they wont get teleported. It also does -1 to the number of players that are queing for that map. Now when a player joins a map it starts a timer other players have 20 seconds to join the map until everyone that did que is teleported. However if 1 player joins a map then leaves it the timer still goes and I have no idea how to stop. Is there a way I can stop it I think by using tables or math and stuff but I dont know how to do that in lua.

Here is the code I am currently using:

while true do
	wait (0.5)
	
	if game.ServerStorage.Map.Players.Value == 1 then
		
	
	
	wait (1)
	game.ServerStorage.Map.Time.Value = 19

	wait (1)
	game.ServerStorage.Map.Time.Value = 18
	wait (1)
	game.ServerStorage.Map.Time.Value = 17

	wait (1)
	game.ServerStorage.Map.Time.Value = 16

	wait (1)
	game.ServerStorage.Map.Time.Value = 15

	wait (1)
	game.ServerStorage.Map.Time.Value = 14

	wait (1)
	game.ServerStorage.Map.Time.Value = 13

	wait (1)
	game.ServerStorage.Map.Time.Value = 12

	wait (1)
	game.ServerStorage.Map.Time.Value = 11

	wait (1)
	game.ServerStorage.Map.Time.Value = 10

	wait (1)
	game.ServerStorage.Map.Time.Value = 9

	wait (1)
	game.ServerStorage.Map.Time.Value = 8

	wait (1)
	game.ServerStorage.Map.Time.Value = 7

	wait (1)
	game.ServerStorage.Map.Time.Value = 6

	wait (1)
	game.ServerStorage.Map.Time.Value = 5

	wait (1)
	game.ServerStorage.Map.Time.Value = 4

	wait (1)
	game.ServerStorage.Map.Time.Value = 3

	wait (1)
	game.ServerStorage.Map.Time.Value = 2

	wait (1)

	game.ServerStorage.Map.Time.Value = 1
	wait (1)
	game.ServerStorage.Map.Time.Value = 0