Timer works in test mode, but breaks now that game is live when more players join game

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    The timer script works perfectly in testing, it even works when I test with more than one player.

  2. What is the issue?
    Now that the game is live, I invite folks in to play but then the timer breaks and doesn’t work

  3. What solutions have you tried so far?
    I don’t know what to do ? Honestly if it worked in test mode over and over again with one player and with more than one player it should work when live but it is breaking ? It seems to break when other players are joining in. They should be able to join and wait in the lobby until the next round starts. Which has successfully happened, but then after the round the timer appears to get stuck. Its very disappointing.

local lobby_Duration = 20
local round_Duration = 200
local map_Fol = game.ReplicatedStorage:WaitForChild("Map")
local timerval = game.ReplicatedStorage:WaitForChild("TimerValue")



local function RTimer ()
	while wait() do
		for l = lobby_Duration, 0, -1 do
			timerval.Value = 'Intermission: '..l
			wait(1)

			if l == 0 then
				--local map = map_Fol:WaitForChild('Main') -- change to your map name
				local mapCopy = map_Fol:Clone()
				mapCopy.Name = "mapCopy"
				mapCopy.Parent = game.Workspace
				timerval.Value = 'Teleporting players to '..mapCopy.Name
				wait(1)
				mapCopy.Parent = workspace

		
			
				wait(2)
				local plrs = game.Players:GetChildren()
				
				

				for i = 1, #plrs do

					plrs[i].Character:MoveTo(Vector3.new(-15.254, 6.232, 130.566))
					
		
				end	
				
				local Players = game:GetService("Players")
				local Workspace = game:GetService("Workspace")
				local ReplicatedStorage = game:GetService("ReplicatedStorage")
				local Event = ReplicatedStorage:WaitForChild("DisplayRole")
				local Sword = ReplicatedStorage:WaitForChild("Sword")


				local Killer = nil
				local Survivors = {}
				
				
				function pickPlayers()

					if Killer then
						if Players:FindFirstChild(Killer) then

							if Players[Killer].Bakcpack:FindFirstChild(Sword.Name) then
								Players[Killer].Bakcpack[Sword.Name]:Destroy()
							else
								if Workspace:FindFirstChild(Killer) then
									if Workspace[Killer]:FindFirstChild(Sword.Name) then
										Workspace[Killer][Sword.Name]:Destroy()
									end
								end
							end

						end
					end

					Killer = nil
					Survivors = {}


					local PlayersGroup = Players:GetChildren()
					local KillerID = math.random(1, #PlayersGroup)

					for i, v in pairs(PlayersGroup) do
						if i == KillerID then

							Killer = v.Name


							break
						end
					end

					for i, v in pairs(PlayersGroup) do
						if i == KillerID then

						else
							table.insert(Survivors, v.Name)
						end
					end





					Event:FireClient(Players[Killer], "You are Killer")
					Sword:Clone().Parent = Players[Killer].Backpack
					print("Killer: ".. Killer)
					for i, v in pairs(Survivors) do
						Event:FireClient(Players[v], "You are Survivor")
						print("Survivor: ".. v)

					end

				end



				
					pickPlayers()
				
					

				wait(1)

				for g = round_Duration,0, -1 do
					timerval.Value = 'Round '..g..' seconds left'
					wait(1)

					if g == 0 then
						timerval.Value = 'Round over'
						wait(2)	
						
						local function cleanup()
							game.Workspace.mapCopy:Destroy()
						end
						cleanup()
						timerval.Value = 'Teleporting players to lobby'
						wait(1)
						
						
						for i = 1, #plrs do
							
							plrs[i].Character:MoveTo(Vector3.new(1097.553, -36.89, -26.611))
						end

						--map.Parent = map_Fol
						wait(1)
						-- repeat again
					end
				end
			end
		end
	end
end

spawn(RTimer)

A spawn function can cause massive lag if is ran often, use coroutine.wrap() instead

I do not know how to use that ? You lost me…

I just tried to read up on coroutine wrap and I am utterly lost still. I do not see any examples of coroutine.wrap() being used in a script so its kind of difficult for me to even grasp. I can’t stand it when print statements are used to show how to use code b/c it utterly confuses me, I can’t get a grasp or handle on the code if i can’t see it actually being used. :confused

someFunctionIdk = coroutine.wrap(RTimer)
someFunctionIdk()

Well I don’t know where to write that into the code. I’m just not understanding. I tried to write it in several different ways but it breaks the script.

I’ve been working on trying to write this in. I watched you tube videos that discusses coroutine and I read up on it in the documents for Roblox but nothing makes sense to me so that I can walk away and be able to write this into my existing script here. Can anyone help explain this to me better so that it works with my existing script ?

I appreciate the explanations so far but they aren’t enough for me to understand what I need to do ?

I am starting to get thumbs down in the game now probably because of this so I am going to have to take the game down. I wish there was a way to test this before going live. I’m new at the programming so I would of never known anything about coroutine and that this extra scripting would be needed in my existing script.

I guess the point I am making is how would I have ever known this would be needed in the timer script so that when other players besides me join the game it didn’t break the timer script ? No mention of this until now and that is what is disappointing to me… in all the tutorials I’ve done to learn a round based timer script there wasn’t any mention of it at all. It makes it difficult to learn when the full spectrum of possibilities that are going to occur are not included in the tutorials so that it is getting piecemealed together after the fact. I realize that the tutorials are given by various different folks all at different levels of learning the Lua too so that is to be factored in. But that is why we have the dev forum to get help… Can anyone please help me further ?