Script timeout: exhausted allowed execution time

I am trying to make a script that makes a grid of plates for players to spawn on. However, the code that I have created is too laggy and exhausts the allowed execution time for a script. Does anyone know how to make a more efficient version of the script?

function generatePlates()
	for i, v in pairs(game.Players:GetChildren()) do
		local plate = Instance.new("Part")
		plate.Name = v.Name
		plate.Size = Vector3.new(15, 1, 15)
		plate.Parent = workspace.Plates
		plate.Anchored = true
		plate.Material = Enum.Material.SmoothPlastic
		plate.BrickColor = BrickColor.new("Dark stone grey")
		local spawns = workspace.Spawns:GetChildren()
		repeat
			local selectedSpawn = spawns[math.random(1, #spawns)]
			local spawnPosition = selectedSpawn.Position
			if selectedSpawn.occupied == false then
				plate.Position = spawnPosition
			end
		until selectedSpawn.occupied == false
	end
end

Add a task.wait() part to the end of it.

2 Likes

Thanks! I will try this as soon as I get a chance!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.