Round System not working

if been making a game that teleports players to a map and gives one player a gun the gun ticks and kills him after 30 seconds and then another gun is given to another one of the alive players. tho it doesnt work it says time “exhausted” and everything me and my friend have tried so far hasnt worked right now it just waits a bunch of time then tps players while giving errors and keeps giving players guns
please help

local rep = game:GetService("ReplicatedStorage")
local Lobby = game.Workspace.Lobby
local Maps = rep.Maps:GetChildren()
local status = rep.Status
local rev = rep.Rev
local gunIsActive = nil
local event = rep.Events.AliveCheck
local availablePlayers = {}
local everyoneIsReady = true
local playercount = game.ServerStorage.Playercount
wait(2)


repeat
	print("waiting for players" ..playercount.Value)
	wait(1)
until playercount.Value > 1
while everyoneIsReady == true and playercount.Value > 1 do
	for i = 10, 0, -1 do
		status.Value = "Intermission: " .. i
		task.wait(1)
	end
	local ChosenMap = Maps[math.random(1, #Maps)]
	print(ChosenMap)
	local CloneMap = ChosenMap:Clone()
	
	CloneMap.Parent = game.Workspace
	status.Value = "Next map: ".. ChosenMap.Name
	task.wait(3)
	
	for i, pluh in pairs(game.Players:GetPlayers()) do
		local char = pluh.Character
		if char then
			local HumP = char.HumanoidRootPart
			print("got HUMP")
			HumP.CFrame = CloneMap.TpPoint.CFrame
			
			pluh.Backpack.PlayerStatus.Value = "Alive"
			table.insert(availablePlayers, pluh)
			
			
			
			print(availablePlayers)
			
			
			
			
			
		end
	end
	while #availablePlayers >= 1 do
		repeat 

			local ChosenPlayer = availablePlayers[math.random(1, #availablePlayers)]
			print(availablePlayers)
			gunIsActive = ChosenPlayer.Name
			rev:Clone().Parent = ChosenPlayer.Character

			wait()
		until ChosenPlayer.Backpack.PlayerStatus == "Dead"
	end
	
	gunIsActive = nil
	ChosenMap = nil
end

event.OnServerEvent:Connect(function(player, stat)
	if player.stat == "Dead" then
		table.remove(availablePlayers, player)
		print(player)
	end
end)

1 Like

Where does the “time exhausted” error occur?

1 Like

There is a wait() missing in the while loop. Without it, roblox studio would crash so roblox pauses the script to prevent it

1 Like

i cant really say it says that like 80 times let me screenshot the error
image
clicking the red only shows an empty script

1 Like

does not work even if i add it same error tho

1 Like

image
unless i placed it wrong which i probs did

1 Like

Are there any more errors? Is there something above the stack begin line in the output?

1 Like

all the Print checks are working i really dont know what is not working you just wait an apsurd time then it does what the for loop does at the same time with the while loop and while loop keeps repeating until i turn it off

1 Like

image

here

1 Like

UPDATE i added a wait() on the first for loop and that tps the players and then gives the gun and tps them back at the same space indefenetly while saying another script that wasnt problematic before after that it prints the player list indefenetly every 0.1 seconds
image

image

image

1 Like

For the last photo, try slowing down your script. You have too many events happening at the same time. I am new to coding too, but I had a similar issue with the last photo there with the execution time. Just add delays between important things and that should fix that. Try changing the isntActive loop to something like this:

while isntActive == true do
if script.Parent.Parent == rep then
isntActive = false
wait(1)
end
end

As for the rest, I am unsure how I can help.

1 Like

I did change that script i added a wait() to both and that seems to fix one of the bugs but now it just inf repeats mains scripts repeat until function

1 Like

If the round system is all in one script, put a while true do loop inside, if you haven’t. You could also had a boolValue in replicated storage that is named RoundActive and update it to true and teleports players to the map when there is a round in progress, and when it turns false teleports the players back to the lobby.

2 Likes

Again, I am relatively new to coding, so I am unsure if it will help

1 Like

alr tnx for the tips my friend is working on it rn and we might just start from scratch but will try!

1 Like