Exhausted allowed execution time fix?

I’m trying to make a teleport system that only teleports one player from a team to a part but every time I test it, the output says “Script Timeout: exhausted allowed execution timeout.” How would I fix that?

Script:

local teleblock = workspace.TeleportTest -- Part Player is Teleporting To

wait(15)

while true do
local team = game:GetService("Teams"):WaitForChild("Awaiting Witch"):GetPlayers()
	if #team ~= 0 then
		local playerpicked = math.random(1, #team)
		for i, v in pairs(team) do
			if i == playerpicked then
				v.Character:SetPrimaryPartCFrame(teleblock.CFrame + Vector3.new(0, 4, 0))
				print("Teleport Done")
			end
		end
	end
end

Try doing while wait() do or adding a wait()

2 Likes
while true do
local team = game:GetService("Teams"):WaitForChild("Awaiting Witch"):GetPlayers()
	if #team ~= 0 then
		local playerpicked = math.random(1, #team)
		for i, v in pairs(team) do
			if i == playerpicked then
				v.Character:SetPrimaryPartCFrame(teleblock.CFrame + Vector3.new(0, 4, 0))
				print("Teleport Done")
			end
		end
	end
wait() -- yield, no yielding in a while loop will crash your studio
end

3 Likes

I figured it out right when I posted this! Thank you though! :smiley:

2 Likes