I have no idea why some code lines doesn't execute

Hi i’m doing a round script but somehow my script just simply doesn’t want to run these lines of code :


	game.Workspace.CurrentlyLoaded:ClearAllChildren()
	for i, player in pairs(Players:GetChildren()) do
		local char = player.Character
		char.Humanoid.BreakJointsOnDeath = false
		char.Humanoid.Health = 0
	end	
	for i, player in pairs(Players:GetChildren()) do
		local char = player.Character
		char.HumanoidRootPart.CFrame = LobbySpawn.CFrame
	end	
end	
spawn(roundTimer)

entire script :

local Players = game.Players
local intermisionLegnth = 30
local choosingMapLength = 15
local InRound = game.ReplicatedStorage.InGame
local LobbySpawn = game.Workspace.Lobby.LobbySpawn
local Status = game.ReplicatedStorage.Status
local ChoosingMap = game.ReplicatedStorage.ChoosingMap
local RoundSpawn = game.Workspace.Lobby.LobbySpawn
local minutes = 0
local seconds = 5
local mapChosen = game.ServerStorage["_Colorful Warehouse"]


local function roundTimer()
	while true do
		for i = intermisionLegnth, 0, -1 do
			InRound.Value = false
			wait(1)
			Status.Value = "Intermission ("..i..")"
		end
		ChoosingMap.Value = true
		for i = choosingMapLength, 0, -1 do
			wait(1)
			Status.Value = "Choosing map... ("..i..")"
		end
		Status.Value = "Loading map ..."
		wait(0.5)
		Status.Value = "Loading map .."
		wait(0.5)
		Status.Value = "Loading map ."
		wait(0.5)
		Status.Value = "Loading map"
		wait(0.5)
		Status.Value = "Loaded"
		wait(0.5)
		InRound.Value = true
		ChoosingMap.Value = false
		local pos = {Vector3.new(0,0,0),Vector3.new(0,0,200),Vector3.new(0,0,400),Vector3.new(0,0,600),Vector3.new(0,0,800),Vector3.new(0,0,1000),Vector3.new(0,0,1200),Vector3.new(0,0,1400),Vector3.new(0,0,1600),Vector3.new(0,0,1800),Vector3.new(0,0,2000),Vector3.new(0,0,2200),Vector3.new(0,0,2400),Vector3.new(0,0,2600),Vector3.new(0,0,2800),Vector3.new(0,0,3000),Vector3.new(0,0,3200),Vector3.new(0,0,3400),Vector3.new(0,0,3600),Vector3.new(0,0,3800)}
		for i, player in pairs(Players:GetChildren())do
			local clone = mapChosen:Clone()	
			clone.Parent = game.Workspace.CurrentlyLoaded
			clone:MoveTo(pos[i])
			print("Initiated map"..mapChosen.Name..i)
			local char = player.Character
			char.HumanoidRootPart.CFrame = clone:WaitForChild("Spawn").CFrame
		end
		repeat
		if seconds <= 0 then
			minutes = minutes - 1
			seconds = 59
		else
			seconds = seconds - 1
		end
		if seconds <= 9  then
			Status.Value = tostring(minutes)..":0"..tostring(seconds)
		else
			Status.Value = tostring(minutes)..":"..tostring(seconds)
			end
			wait(1)
		until minutes <= 0 and seconds <= 0
		minutes = 0
		seconds = 5
	end
	game.Workspace.CurrentlyLoaded:ClearAllChildren()
	for i, player in pairs(Players:GetChildren()) do
		local char = player.Character
		char.Humanoid.BreakJointsOnDeath = false
		char.Humanoid.Health = 0
	end	
	for i, player in pairs(Players:GetChildren()) do
		local char = player.Character
		char.HumanoidRootPart.CFrame = LobbySpawn.CFrame
	end	
end	
spawn(roundTimer)

I get no errors in the output, and i’m sure that the variables, everything are correct, also i’m almost sure that no scripts interfere with this one, i’m not using breakpoints and i’d like some help because i’ve been trying to figure this out for the past 3 hours but I can’t find why :frowning: (maybe cuz i’m a beginner lol)

If you need more infos to solve this problem, ask me in the replies, thanks !

Game link so you can see for yourself the problem: Atmos [Indev] - Roblox

oh also it’s normal that a round only lasts for 5 seconds, it’s for testing purposes and to make it faster

Try to follow this tips:

Change local Players = game.Players to local Players = game:GetService(“Players”).

Change game.Workspace.CurrentlyLoaded:ClearAllChildren() to

for i, object in pairs(workspace.CurrentlyLoaded:GetChildren()) do
	object:Destroy()
end

Change Players:GetChildren() to Players:GetPlayers()

Let me know if these tips work.

1 Like

Thanks for the tips but it sadly didn’t change anything :frowning:

Oh, I just found the error.
while true do end yields infinitely and the rest of the code won’t work.

pcall only works if there is an error in the code. As he said, there are no errors in the output.

at this point even an error is more helpful than nothing :rofl: I still can’t find why, the bits of code themselves work in another game

I removed the local function because it’s useless but nothing changed

code now:

local Players = game:GetService("Players")
local intermisionLegnth = 30
local choosingMapLength = 15
local InRound = game.ReplicatedStorage.InGame
local LobbySpawn = game.Workspace.Lobby.LobbySpawn
local Status = game.ReplicatedStorage.Status
local ChoosingMap = game.ReplicatedStorage.ChoosingMap
local RoundSpawn = game.Workspace.Lobby.LobbySpawn
local minutes = 0
local seconds = 5
local mapChosen = game.ServerStorage["_Colorful Warehouse"]

while true do
		for i = intermisionLegnth, 0, -1 do
			InRound.Value = false
			wait(1)
			Status.Value = "Intermission ("..i..")"
		end
		ChoosingMap.Value = true
		for i = choosingMapLength, 0, -1 do
			wait(1)
			Status.Value = "Choosing map... ("..i..")"
		end
		Status.Value = "Loading map ..."
		wait(0.5)
		Status.Value = "Loading map .."
		wait(0.5)
		Status.Value = "Loading map ."
		wait(0.5)
		Status.Value = "Loading map"
		wait(0.5)
		Status.Value = "Loaded"
		wait(0.5)
		InRound.Value = true
		ChoosingMap.Value = false
		local pos = {Vector3.new(0,0,0),Vector3.new(0,0,200),Vector3.new(0,0,400),Vector3.new(0,0,600),Vector3.new(0,0,800),Vector3.new(0,0,1000),Vector3.new(0,0,1200),Vector3.new(0,0,1400),Vector3.new(0,0,1600),Vector3.new(0,0,1800),Vector3.new(0,0,2000),Vector3.new(0,0,2200),Vector3.new(0,0,2400),Vector3.new(0,0,2600),Vector3.new(0,0,2800),Vector3.new(0,0,3000),Vector3.new(0,0,3200),Vector3.new(0,0,3400),Vector3.new(0,0,3600),Vector3.new(0,0,3800)}
		for i, player in pairs(Players:GetPlayers())do
			local clone = mapChosen:Clone()	
			clone.Parent = game.Workspace.CurrentlyLoaded
			clone:MoveTo(pos[i])
			print("Initiated map"..mapChosen.Name..i)
			local char = player.Character
			char.HumanoidRootPart.CFrame = clone:WaitForChild("Spawn").CFrame
		end
		repeat
		if seconds <= 0 then
			minutes = minutes - 1
			seconds = 59
		else
			seconds = seconds - 1
		end
		if seconds <= 9  then
			Status.Value = tostring(minutes)..":0"..tostring(seconds)
		else
			Status.Value = tostring(minutes)..":"..tostring(seconds)
			end
			wait(1)
		until minutes <= 0 and seconds <= 0
		minutes = 0
		seconds = 5
	end
	for i, object in pairs(workspace.CurrentlyLoaded:GetChildren()) do
		object:Destroy()
	end
	for i, player in pairs(Players:GetPlayers()) do
		local char = player.Character
		char.Humanoid.BreakJointsOnDeath = false
		char.Humanoid.Health = 0
	end	
	for i, player in pairs(Players:GetPlayers()) do
		local char = player.Character
		char.HumanoidRootPart.CFrame = LobbySpawn.CFrame
	end	


Does the script work correctly?

1 Like

OH wait i think I found actually you’re correct I think the bits of code are not present in the while true do loop

What does ‘bits’ mean? -------

1 Like

the part that won’t run, i’ll definitely try to indent my code better lol i thought the last end was for the while true do loop but actually it’s the for loop